get bluetooth address

public static String getBluetoothAddress() {
        String bluetoothAddress = "";
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        System.out.println(">>>>>>>>>> android_sdk_version=" + Build.VERSION.SDK_INT);
        if(Build.VERSION.SDK_INT < 23){
            bluetoothAddress =  bluetoothAdapter.getAddress();
        }else {
            Object bluetoothManagerService = new Mirror().on(bluetoothAdapter).get().field("mService");
            if (bluetoothManagerService != null) {
                Object address = new Mirror().on(bluetoothManagerService).invoke().method("getAddress").withoutArgs();
                if (address != null && address instanceof String) {
                    bluetoothAddress = (String) address;
                }
            }
        }
        return bluetoothAddress;
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326119996&siteId=291194637