Skip to content
Snippets Groups Projects
Verified Commit 6e55341e authored by Julian Dehm's avatar Julian Dehm
Browse files

If all else fails use reflection to get the Bluetooth address.

parent f78f0652
No related tags found
No related merge requests found
Pipeline #
...@@ -129,6 +129,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> { ...@@ -129,6 +129,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
@Nullable @Nullable
String getBluetoothAddress() { String getBluetoothAddress() {
String address = AndroidUtils.getBluetoothAddress(appContext, adapter); String address = AndroidUtils.getBluetoothAddress(appContext, adapter);
LOG.info("Bluetooth address:" + address);
return address.isEmpty() ? null : address; return address.isEmpty() ? null : address;
} }
......
...@@ -6,6 +6,7 @@ import android.os.Build; ...@@ -6,6 +6,7 @@ import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
import java.io.File; import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
...@@ -41,6 +42,18 @@ public class AndroidUtils { ...@@ -41,6 +42,18 @@ public class AndroidUtils {
address = Settings.Secure.getString(ctx.getContentResolver(), address = Settings.Secure.getString(ctx.getContentResolver(),
"bluetooth_address"); "bluetooth_address");
if (isValidBluetoothAddress(address)) return address; if (isValidBluetoothAddress(address)) return address;
try {
final Field mServiceField;
mServiceField = BluetoothAdapter.class.getDeclaredField("mService");
mServiceField.setAccessible(true);
final Object mService = mServiceField.get(adapter);
if (mService == null)
return "";
address = (String) mService.getClass().getMethod("getAddress").invoke(mService);
if (isValidBluetoothAddress(address)) return address;
} catch (Exception e) {
// Nothing we can do about it.
}
// Let the caller know we can't find the address // Let the caller know we can't find the address
return ""; return "";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment