- 获取蓝牙适配器BluetoothAdpater
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothAdapter adapter = (BluetoothAdapter) getApplicationContext().getSystemService(BLUETOOTH_SERVICE);
- 安卓6以后的版本使用此方法拿不到真实的MAC地址
String macAddr = adapter.getAddress();
- 需要采用以下镜像来获取
Object bluetoothManageService = new Mirror().on(adapter).get().field("mService"); if (bluetoothManageService == null) return null; Object address = new Mirror().on(bluetoothManageService).invoke().method("getAddress").withoutArgs(); if (address != null && address instanceof String) { return (String) address; } else { return null; }
- 最后别忘了添加依赖关系
implementation 'net.vidageek:mirror:1.6.1'
文章来源: 安卓获取手机本身的蓝牙MAC地址