Huawei Mate 10 Pro phone 找不到带有 altbeacon 的信标。其他 phone 做

Huawei Mate 10 Pro phone doesn't find beacons with altbeacon. Other phones do

我正在使用 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);
}

它开始在我的应用程序中调用此函数 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);
        }
    }
}

但很多时候,我得到了大小为 0 的集合。甚至认为我在范围内有 2 个信标。 我还尝试使用 LG Nexus 5 和 LeEco LePro2 以及 return 正确的信标列表。华为有什么问题?

如果有帮助,这是我配置的信标布局列表:

   //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://nl.aliexpress.com/item/3-pcs-BLE-4-0-Base-Station-Ebeoo-iBeacon-USB/32752285433.html?spm=a2g0s.9042311.0.0.g1aZkv

这张图片显示了它找到的内容,与其他图片相比: 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 4.3+ 和蓝牙低功耗芯片组的设备都可以使用此库检测信标。根据 Google Play 商店,截至 2017 年 8 月,这大约占 Android 设备的 92%。

要作为信标传输,需要 Android 5.0+ 和支持低功耗蓝牙外设模式的固件。

To find out if your smart phone or tablet can work with Bluetooth LE: Go to the Google Play store and install the free app “BLE Checker” on your Android device. The app is simple – it tells you whether your device supports Bluetooth LE or not and that is all it does.

我无法在 Mate10 上测试你的代码,因为我现在没有,但我认为你的问题是关于 android 8 阅读这篇 link 关于 android 的变化8

http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8

使用该库的应用需要升级到 2.12+ 版才能在 Android 8 台设备上进行后台检测。版本 2.13+ 进一步增强了 Android 8.1 关闭屏幕扫描的限制。

dependencies {
  compile 'org.altbeacon:android-beacon-library:2+'
}

根据问题下方的评论,华为的检测是 间歇性的,并且代码在 5 秒的扫描中只有 5-10% 的机会检测到信标,在代码放弃了哪一点。

有些蓝牙芯片在开始扫描后检测到第一个信标的速度很慢。这可能是您必须学会接受的硬件限制。

我建议您将代码修改为:

  1. 寻找信标的时间远远超过 5 秒,并在找到信标后立即显示结果。这样它在快速设备上会很快,在慢速设备上会很慢。

  2. 在应用程序进入后台之前,不要解除与信标管理器的绑定。这样,它已经在扫描,以防您点击重试,并且不会延迟启动扫描。

  3. 如果您可以控制硬件信标的配置,请确保它以尽可能高的速率传输。某些信标设置为每 1-5 秒仅传输一次,这会降低在短时间间隔内检测到数据包的机会。使信标传输的频率越高,它在 5 秒内被检测到的几率就越大。