Get Bluetooth local mac address in Marshmallow

前端 未结 8 479
半阙折子戏
半阙折子戏 2020-11-29 06:23

Pre Marshmallow my app would obtain it\'s device MAC address via BluetoothAdapter.getDefaultAdapter().getAddress().

Now with Marshmallow Android is retu

相关标签:
8条回答
  • 2020-11-29 07:07

    As it turns out, I ended up not getting the MAC address from Android. The bluetooth device ended up providing the Android device MAC address, which was stored and then used when needed. Yeah it seems a little funky but on the project I was on, the bluetooth device software was also being developed and this turned out to be the best way to deal with the situation.

    0 讨论(0)
  • 2020-11-29 07:12

    First the following permissions have to be added to Manifest;

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS" />
    

    Then,

    public static final String SECURE_SETTINGS_BLUETOOTH_ADDRESS = "bluetooth_address";
    
    String macAddress = Settings.Secure.getString(getContentResolver(), SECURE_SETTINGS_BLUETOOTH_ADDRESS);
    

    After that the application has to be signed with OEM / System key. Tested and verified on Android 8.1.0.

    0 讨论(0)
提交回复
热议问题