当我尝试在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。