当我尝试通过这种方式获取 Android O 设备上的蓝牙地址时:
private String getBlutoothAddress(Context mContext){
// Check version API Android
BluetoothAdapter myBluetoothAdapter;
String macAddress;
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= android.os.Build.VERSION_CODES.M) {
macAddress = Settings.Secure.getString(mContext.getContentResolver(), "bluetooth_address");
} else {
// Do this for phones running an SDK before lollipop
macAddress = myBluetoothAdapter.getAddress();
}
}
上面的所有代码都运行良好,直到我将该代码用于 Android O (8.0),它返回 macAddress = null。
您的应用程序需要保存LOCAL_MAC_ADDRESS
允许:
设置.安全.蓝牙地址:设备蓝牙MAC地址。在 O 中,这仅适用于持有 LOCAL_MAC_ADDRESS 权限的应用程序。
https://android-developers.googleblog.com/2017/04/changes-to-device-identifiers-in.html https://android-developers.googleblog.com/2017/04/changes-to-device-identifiers-in.html
但是,那LOCAL_MAC_ADDRESS权限是系统权限 http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/res/AndroidManifest.xml#3027所以实际上你的应用程序不能拥有它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)