【发布时间】:2018-03-20 19:34:03
【问题描述】:
我正在使用 altbeacon:https://altbeacon.github.io/android-beacon-library/ 我绑定了我的 beaconManager。然后我称之为:
public void startListeningForBeacons(RangeNotifier rangeNotifier) {
try {
Region region = new Region("all-beacons-region", null, null, null);
// Tells the BeaconService to start looking for beacons that match the passed Region object
beaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
// Specifies a class that should be called each time the BeaconService gets ranging data, once per second by default
beaconManager.addRangeNotifier(rangeNotifier);
}
在我的应用程序类中开始调用这个函数:
@Override
public void didRangeBeaconsInRegion(final Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Log.i("BluetoothService", "BluetoothService region The first beacon I see is about " + beacons.iterator().next().getDistance() + " meters away.");
if (didRangeBeaconsCallback != null)
didRangeBeaconsCallback.rangeCalled(beacons, region);
}else {
Log.i("BluetoothService", "BluetoothService region NO BEACONS: " + beacons.size());
if(PSBluetoothService.getInstance(PSApplicationClass.this).beaconUUID != null){
if (didRangeBeaconsCallback != null)
didRangeBeaconsCallback.rangeCalled(null, null);
}
}
}
但很多时候,我会返回大小为 0 的集合。即使我认为我的范围内有 2 个信标。 我还尝试了 LG Nexus 5 和 LeEco LePro2,它们都返回了正确的信标列表。华为可能会出什么问题?
如果有帮助,这是我配置的信标布局列表:
//sets the types of beacons that the library is searching for
public void setNeededTypesOfBeacons() {
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(BeaconParser.ALTBEACON_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.getBeaconParsers().add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
}
这是一张显示它发现的图片,与其他图片相比: https://s3.amazonaws.com/uploads.hipchat.com/39260/829560/5FNgB6ARACpywWv/upload.png
编辑:
如果有帮助,请使用此逻辑制作示例应用程序:https://www.dropbox.com/s/4ddt9mhn7zdi9gd/Beacon.zip?dl=0
即使离开它扫描很长时间,仍然没有结果,当它没有找到它们时:
03-20 12:30:24.542: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:25.644: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:26.749: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:27.855: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:28.960: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:30.071: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:31.174: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:32.277: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:33.379: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:34.486: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:35.588: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:36.696: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:37.803: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:38.906: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:40.012: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:41.210: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:42.313: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:43.418: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:44.522: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:45.628: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:46.734: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:47.839: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:48.943: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:50.061: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:50.061: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:51.165: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:52.268: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:53.372: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
03-20 12:30:54.476: I/BluetoothService(10806): BluetoothService region NO BEACONS: 0
【问题讨论】:
-
运行良好的手机是否有 Android 8+?您是否在前台可靠地检测到华为?您使用的是哪个版本的 Android 信标库?
-
@davidgyoung 我正在使用:'org.altbeacon:android-beacon-library:2+' 其他 2 部手机有 Android 6.0。我可以将手机连接到蓝牙耳机或其他手机。但是因为我没有对上面的信标进行检测。
-
您说“很多时候我会返回大小为 0 的集合。”这似乎表明它有时适用于华为设备。您能否描述一下何时有效与何时无效?
-
嗯,我有一个重试按钮,它会断开连接,重新绑定信标管理器,再次开始搜索,持续 5 秒。在它显示结果之后,或“未找到信标”,就像在图片中一样。使用重试按钮。如果我重试 10 次,它会找到一次。我的问题是,一旦找到一个。我需要获取蓝牙设备,更改它的名称,更改 uuid(在按下的列表项上)。完成后,我再次扫描信标,并尝试找到它。在 uuid 和名称(或只是名称,没关系)得到更改后,我再次搜索。
-
因为通常它只会每 10 次尝试“找到”一个集合。当然,我的第二次尝试会失败,因为这个工作一次又一次的几率是多少。如果我几乎找不到他们的 5-10% 的变化
标签: android bluetooth beacon ibeacon-android altbeacon