【问题标题】:Huawei Mate 10 Pro phone doesn't find beacons with altbeacon. Other phones do华为 Mate 10 Pro 手机找不到带有 altbeacon 的信标。其他手机可以
【发布时间】: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://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 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


【解决方案1】:

根据问题下方的 cmets,在华为上的检测是间歇性,代码在 5 秒扫描内只有 5-10% 的机会检测到信标,此时代码给出向上。

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

我建议您将代码修改为:

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

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

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

【讨论】:

  • 谢谢,我将时间增加到 15 秒,但到目前为止是一样的。我会尝试移除解除绑定,然后告诉你会发生什么
  • 不,即使我无限期地离开它。编辑并添加了关于我的问题的日志。
  • 在华为上运行图书馆的参考应用会看到什么:github.com/altbeacon/android-beacon-library-reference
  • 它可以工作,这是电池设置的原因/它具有启动模式,如果您没有将应用程序设置为“手动”处理程序并将其设置为在后台工作并自动启动。它行不通。类似于节电程序的工作原理
【解决方案2】:

任何搭载 Android 4.3+ 和蓝牙低功耗芯片组的设备都可以使用此库检测信标。根据 Google Play 商店的数据,截至 2017 年 8 月,这约占 Android 设备的 92%。

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

要了解您的智能手机或平板电脑是否可以使用蓝牙 LE: 前往 Google Play 商店并安装免费应用程序“BLE Checker” 你的安卓设备。该应用程序很简单——它会告诉您您的 设备是否支持蓝牙 LE,仅此而已。

我无法在 Mate10 上测试你的代码,因为我现在没有,但我认为你关于 android 8 的问题阅读了这个关于 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+'
}

【讨论】:

  • 我编辑了我的标题。这个问题在华为 Mate 10 Pro 上遇到,它是新的并且支持 BLE 的 Android 8.0
  • 另外,如果我使用蓝牙适配器和发现,我可以配对、绑定,甚至改变信标的特性。只有为他们测距,我才有问题
  • @rosualin 请使用 BLE 检查器检查 mate10
  • 我的意思是我已经在 LightBlue 和 BeaconManager 中使用过它。现在尝试了 BLE Checker,它说它支持。
  • 有时它确实找到了 1 个信标,但需要很长时间,而且由于它是永久测距的,它会相对较快地消失。我试图理解为什么我不能从它那里得到信号,就像在 Nexus 或 LeEco 上一样
猜你喜欢
  • 1970-01-01
  • 2021-03-09
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 2021-10-14
  • 2015-08-24
  • 2019-04-13
  • 1970-01-01
相关资源
最近更新 更多