Secure.getString(mContext.getContentResolver(),"bluetooth_address")在Android O中返回null [英] Secure.getString(mContext.getContentResolver(), "bluetooth_address") return null in Android O

查看:589
本文介绍了Secure.getString(mContext.getContentResolver(),"bluetooth_address")在Android O中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过这种方式在Android O设备上获取蓝牙地址时:

When I'm trying to get Blutooth Address on Android O device by this way:

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();            
    }
}

以上所有代码仍然运行良好,但我仍将该代码用于Anroid O(8.0),返回的是macAddress = null.

All code above working well still I use that code for Anroid O (8.0) it's return macAddress = null.

推荐答案

您的应用需要持有LOCAL_MAC_ADDRESS权限:

Your app would need to hold the LOCAL_MAC_ADDRESS permission:

Settings.Secure.bluetooth_address :设备蓝牙MAC地址.在O中,此功能仅对拥有LOCAL_MAC_ADDRESS权限的应用可用.

Settings.Secure.bluetooth_address: Device Bluetooth MAC address. In O, this is only available to apps holding the LOCAL_MAC_ADDRESS permission.

https://android-developers. googleblog.com/2017/04/changes-to-device-identifiers-in.html

但是, LOCAL_MAC_ADDRESS权限为系统权限,因此实际上您的应用无法拥有它.

However, the LOCAL_MAC_ADDRESS permission is a system permission so in practice your app cannot have it.

这篇关于Secure.getString(mContext.getContentResolver(),"bluetooth_address")在Android O中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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