由于棉花糖使用 BluetoothAdapter.getDefaultAdapter().startDiscovery(); 更新蓝牙发现;被打破 [英] Since marshmallow update Bluetooth discovery using BluetoothAdapter.getDefaultAdapter().startDiscovery(); is broken

查看:37
本文介绍了由于棉花糖使用 BluetoothAdapter.getDefaultAdapter().startDiscovery(); 更新蓝牙发现;被打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用蓝牙并连接到设备的应用程序,使用 BluetoothAdapter.getDefaultAdapter().startDiscovery() 找不到任何设备;在发现之前它运行良好.也尝试过其他应用程序,它在其他应用程序中也不起作用.但是我尝试配对的设备(Arduino bt-module)可以在 Android 设置中找到.知道我可以尝试什么吗?我实现了 http://developer.android.com/guide/topics/connectivity/bluetooth 中描述的所有内容.html 并且它在更新之前工作.

I have an app using bluetooth and connecting to devices, can'f find any devices using BluetoothAdapter.getDefaultAdapter().startDiscovery(); It worked fine just before discovery. Tried also other apps, it doesn't work in other apps as well. But the device I try to pair (Arduino bt-module) can be found in Android settings. Any idea what could I try? I implemented everything like described on http://developer.android.com/guide/topics/connectivity/bluetooth.html and it worked before the update.

推荐答案

蓝牙适配器在 Android 6.0 中发生了变化

Bluetooth Adapter has been change in Android 6.0

需要设置权限ACCESS_FINE_LOCATION或者ACCESS_COARSE_LOCATION权限并且需要使用BluetoothLeScanner.startScan() 方法开始扫描.

以下是更改日志的描述:

为了向用户提供更好的数据保护,在 Android 6.0 中,Android 删除了使用 Wi-Fi 和蓝牙 API 的应用对设备本地硬件标识符的编程访问.WifiInfo.getMacAddress() 和 BluetoothAdapter.getAddress() 方法现在返回一个常量值 02:00:00:00:00:00.

To provide users with greater data protection, in Android 6.0, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.

要通过蓝牙和 Wi-Fi 扫描访问附近外部设备的硬件标识符,您的应用现在必须具有 ACCESS_FINE_LOCATION 或 ACCESS_COARSE_LOCATION 权限:

To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions:

WifiManager.getScanResults()
BluetoothDevice.ACTION_FOUND
BluetoothLeScanner.startScan()

注意:当运行 Android 6.0(API 级别 23)的设备启动后台 Wi-Fi 或蓝牙扫描时,外部设备可以看到该操作源自随机 MAC 地址.

Note: When a device running Android 6.0 (API level 23) initiates a background Wi-Fi or Bluetooth scan, the operation is visible to external devices as originating from a randomized MAC address.

您可以从此链接获取更多详细信息:http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html

You can get more details from this link : http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html

这篇关于由于棉花糖使用 BluetoothAdapter.getDefaultAdapter().startDiscovery(); 更新蓝牙发现;被打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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