蓝牙LE ScanFilters不要版本的Andr​​oid M工作 [英] Bluetooth LE ScanFilters don't work on Android M

查看:2011
本文介绍了蓝牙LE ScanFilters不要版本的Andr​​oid M工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code对我的Nexus的伟大工程,9运行Android 5.1.1(构建LMY48M),但不会上运行的Nexus 9上班的Andr​​oid 6.0(编译MPA44l)

The following code works great on my Nexus 9 running Android 5.1.1 (Build LMY48M), but won't work on a Nexus 9 running Android 6.0 (Build MPA44l)

List<ScanFilter> filters = new ArrayList<ScanFilter>();
ScanSettings settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)).build();
ScanFilter.Builder builder = new ScanFilter.Builder();
builder.setManufacturerData((int) 0x0118, new byte[]{(byte) 0xbe, (byte) 0xac}, new byte[]{(byte) 0xff, (byte)0xff});
ScanFilter scanFilter = builder.build();
filters.add(scanFilter);
mBluetoothLeScanner.startScan(filters, settings, new ScanCallback() {
  ...
});

在Android的5.x的,上面的code产生当一家厂商的广告匹配扫描过滤器被认为是一个回调。 (请参见下面的例子logcat的输出。)在Nexus的9 MPA44l,没有回调接收。如果您注释掉扫描过滤器,回调成功地接收到了Nexus 9。

On Android 5.x, the above code yields a callback when a manufacturer advertisement matching the scan filter is seen. (See example Logcat output below.) On the Nexus 9 with MPA44l, no callbacks are received. If you comment out the scan filter, callbacks are received successfully on the Nexus 9.

09-22 00:07:28.050    1748-1796/org.altbeacon.beaconreference D/BluetoothLeScanner﹕ onScanResult() - ScanResult{mDevice=00:07:80:03:89:8C, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={280=[-66, -84, 47, 35, 68, 84, -49, 109, 74, 15, -83, -14, -12, -111, 27, -87, -1, -90, 0, 1, 0, 1, -66, 0]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-64, mTimestampNanos=61272522487278}

有人看到ScanFilters上版本的Andr​​oid M工作?

Has anybody seen ScanFilters work on Android M?

推荐答案

问题不扫描过滤器,但是,当该应用是在后台扫描过滤器仅被使用。与版本的Andr​​oid M开始,在背景中的蓝牙LE扫描阻止,除非应用程序有以下两种权限之一:

The problem was not the scan filter, but that the scan filter was only being used when the app was in the background. Starting with Android M, Bluetooth LE scanning in the background is blocked unless the app has one of the following two permissions:

android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION

我是测试并没有要求这两种权限,所以才没有在后台运行在Android M.(唯一一次扫描过滤器是活跃的)添加第一个该应用程序解决了这个问题。

The app I was testing did not request either of these permissions, so it did not work in the background (the only time the scan filter was active) on Android M. Adding the first one solved the problem.

我意识到这是问题,因为我看到的logcat以下行:

I realized this was the problem because I saw the following line in Logcat:

09-22 22:35:20.152  5158  5254 E BluetoothUtils: Permission denial: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results

在这里看到的细节:<一href=\"https://$c$c.google.com/p/android-developer-$p$pview/issues/detail?id=2964\">https://$c$c.google.com/p/android-developer-$p$pview/issues/detail?id=2964

这篇关于蓝牙LE ScanFilters不要版本的Andr​​oid M工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆