我的应用程序可以通过BluetoothAdapter.getDefaultAdapter().getAddress().获得它的设备MAC地址
现在,随着Marshmallow的出现,安卓系统正在返回02:00:00:00:00:00。
我看到了一些链接(抱歉,不知道现在在哪里),上面说您需要添加附加权限。
<uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS"/> 才能得到它。不过,这对我没有用。
是否需要额外的许可才能获得mac地址?
我不确定这是否与此相关,但舱单也包括
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>那么有什么办法可以得到本地的蓝牙mac地址吗?
发布于 2018-03-08 13:01:10
请使用以下代码获取蓝牙mac地址。如果有什么问题请告诉我。
private String getBluetoothMacAddress() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String bluetoothMacAddress = "";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
try {
Field mServiceField = bluetoothAdapter.getClass().getDeclaredField("mService");
mServiceField.setAccessible(true);
Object btManagerService = mServiceField.get(bluetoothAdapter);
if (btManagerService != null) {
bluetoothMacAddress = (String) btManagerService.getClass().getMethod("getAddress").invoke(btManagerService);
}
} catch (NoSuchFieldException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
} else {
bluetoothMacAddress = bluetoothAdapter.getAddress();
}
return bluetoothMacAddress;
}https://stackoverflow.com/questions/33377982
复制相似问题