Android 8.0 Get BluetoothAddress
//Make Sure Bluetooth is opened
private String getBluetoothAddress(BluetoothAdapter adapter) {
if (adapter == null) {
return null;
}
Class<? extends BluetoothAdapter> btAdapterClass = adapter.getClass();
try {
Field mServiceField = adapter.getClass().getDeclaredField("mService");
mServiceField.setAccessible(true);
Object btManagerService = mServiceField.get(adapter);
if (btManagerService != null) {
return (String) btManagerService.getClass().getMethod("getAddress").invoke(btManagerService);
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
LogWriter.writeLog(TAG, e.getMessage());
return null;
}
}