我正试图通过这种方式获取蓝牙mac地址:
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String address = mBluetoothAdapter.getAddress();
但是它总是返回:
02:00:00:00:00:00
为什么?这是一种安全政策吗?
谢谢。
贾科莫
答案 0 :(得分:0)
答案摘录:
private String getBluetoothMac(final Context context) {
String result = null;
if (context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH)
== PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Hardware ID are restricted in Android 6+
// https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id
// Getting bluetooth mac via reflection for devices with Android 6+
result = android.provider.Settings.Secure.getString(context.getContentResolver(),
"bluetooth_address");
} else {
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
result = bta != null ? bta.getAddress() : "";
}
}
return result;
}