首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >华为Mate 10 Pro手机没有找到带有信标的信标。其他手机也有

华为Mate 10 Pro手机没有找到带有信标的信标。其他手机也有
EN

Stack Overflow用户
提问于 2018-03-16 15:14:25
回答 2查看 1.1K关注 0票数 0

我使用的是阿尔特信标:https://altbeacon.github.io/android-beacon-library/,我绑定了我的beaconManager。然后我称之为:

代码语言:javascript
复制
   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);
}

它开始在我的应用程序类中调用这个函数:

代码语言:javascript
复制
  @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码的收藏。即使我有两个信标在射程内。我还尝试使用LG Nexus 5和LeEco LePro2,两者都返回正确的信标列表。当涉及到华为时,会有什么问题呢?

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

代码语言:javascript
复制
   //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

即使离开它扫描很长一段时间,仍然没有结果,当它找不到它们:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-19 17:36:22

基于以下问题的评论,对华为的检测是断断续续的,代码只有5-10%的机会在5秒的扫描时间内检测到信标,此时代码就放弃了。

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

我建议你重新修改代码,以便:

  1. 寻找比5秒长得多的信标,并在找到一个信标后立即显示结果。这样,它在快速设备上将是快速的,在慢设备上将是慢的。
  2. 在应用程序进入后台之前,不要从信标管理器中解除绑定。这样,它已经在扫描,以防你点击重试,并且在启动扫描时不会有延迟。
  3. 如果您控制硬件信标的配置,请确保它以尽可能高的速率传输。一些信标被设置为每1-5秒只发送一次,这降低了在短时间间隔内检测数据包的机会。你越频繁地发射信标,它在5秒内被检测到的几率就越大。
票数 1
EN

Stack Overflow用户

发布于 2018-03-16 15:16:31

任何带有Android 4.3+和蓝牙低能芯片组的设备都可以用这个库检测信标。据谷歌游戏商店( Google )的数据,截至2017年8月,这一比例约为安卓设备的92 %。

作为信标传输,安卓5.0+和固件支持蓝牙低能量外围模式是必要的。

要想知道你的智能手机或平板电脑是否可以使用蓝牙,请访问Google商店,在你的安卓设备上安装免费应用程序“检查器”。这个应用程序很简单-它告诉你你的设备是否支持蓝牙乐,这就是它所做的一切。

我不能在Mate10上测试您的代码,因为我现在没有代码,但是我认为您对于android 8的问题在于阅读了有关android 8上的更改的链接

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

使用该库的应用程序将需要升级到2.12+版本,以便在Android8设备上检测到背景信息。版本2.13+为Android8.1增加了进一步的增强,限制了屏幕关闭后的扫描。

代码语言:javascript
复制
dependencies {
  compile 'org.altbeacon:android-beacon-library:2+'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49324089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档