Huawei Mate 10 Pro手机找不到带有altbeacon的信标.其他手机呢 [英] Huawei Mate 10 Pro phone doesn't find beacons with altbeacon. Other phones do
问题描述
我正在使用altbeacon: https://altbeacon.github.io/android-beacon-library/我绑定我的beaconManager.然后我称之为:
I am using altbeacon: https://altbeacon.github.io/android-beacon-library/ I bind my beaconManager. and then I call this:
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);
}
哪个会在我的应用程序类中开始调用此函数:
Which starts calling this function inside my application class:
@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);
}
}
}
但是很多时候,我回去了o大小为0的集合.甚至以为我有2个信标在范围之内.我还尝试了LG Nexus 5和LeEco LePro2,并且都返回了正确的信标列表.关于华为,可能会出什么问题?
But a lot of times, I get back o collection of size 0. Even thought I have 2 beacons in range. I also tried with a LG Nexus 5 and a LeEco LePro2 and both return the correct list of beacons. What might go wrong when it comes to the Huawei?
如果有帮助,这是我配置的信标布局的列表:
If it helps, this is the list of beacon layouts I configure:
//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
This is a picture showing what it finds, compared to the others: https://s3.amazonaws.com/uploads.hipchat.com/39260/829560/5FNgB6ARACpywWv/upload.png
如果有帮助,请使用以下逻辑制作一个示例应用程序: https://www.dropbox.com/s/4ddt9mhn7zdi9gd/Beacon.zip?dl=0
Made a sample app, just with this logic, if it helps: https://www.dropbox.com/s/4ddt9mhn7zdi9gd/Beacon.zip?dl=0
即使长时间扫描也找不到结果,但仍然没有结果:
Even when leaving it scan for a long time, still no results, when it doesn't find them:
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
推荐答案
基于问题下方的注释,华为的检测是间歇性,而该代码只有5-10%的机会被检测到扫描5秒钟后发出信标,此时代码将放弃.
Based on comments below the question, the detection is intermittent on Huawei and the code only has a 5-10% chance of detecting a beacon in 5 seconds of scanning, at which point the code gives up.
有些蓝牙芯片开始扫描后,检测第一个信标的速度很慢.这可能是您必须学会使用的硬件限制.
There are some bluetooth chips that are slow to detect the first beacon after starting scanning. This may be a hardware limitation that you must learn to live with.
我建议您将代码重做为:
I would suggest you rework the code to:
-
查找信标的时间长于5秒钟,并在找到信标后立即显示结果.这样,它将在快速设备上快速运行,而在慢速设备上缓慢运行.
Look for beacons for much longer than 5 seconds and show results as soon as you find one. This way it will be fast on fast devices and slow on slow devices.
在应用程序进入后台之前,不要与信标管理器解除绑定.这样,它已经在扫描以防您重试,并且不会延迟启动扫描.
Don't unbind from the beacon manager until the app goes to the background. This way, it is already scanning in case you hit retry, and there won't be a delay in starting up scanning.
如果您可以控制硬件信标的配置,请确保其以尽可能高的速率传输.一些信标设置为每1-5秒仅发送一次,这减少了在短时间间隔内检测到数据包的机会.信标传输的频率越高,在5秒钟内检测到它的几率就越大.
If you have control over the configuration of the hardware beacon, make sure it is transmitting at the highest rate possible. Some beacons are set to transmit only once every 1-5 seconds, which decreases the chance of detecting a packet within a short time interval. The more often you make the beacon transmit, the greater the odds of it getting detected within 5 seconds.
这篇关于Huawei Mate 10 Pro手机找不到带有altbeacon的信标.其他手机呢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!