相关疑难解决方法(0)

蓝牙LE扫描在后台无法在Android M上运行

以下代码适用于运行Android 5.1.1(Build LMY48M)的Nexus 9,但不适用于运行Android 6.0的Nexus 9(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() {
  ...
});
Run Code Online (Sandbox Code Playgroud)

在Android 5.x上,当看到与扫描过滤器匹配的制造商广告时,上述代码产生回调.(参见下面的示例Logcat输出.)在带有MPA44l的Nexus 9上,没有收到回调.如果您注释掉扫描过滤器,则会在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, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-bluetooth android-6.0-marshmallow

23
推荐指数
3
解决办法
3万
查看次数