您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 3浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

安卓获取手机本身的蓝牙MAC地址

仙剑情缘 发布时间:2018-06-17 15:53:40 ,浏览量:3

  • 获取蓝牙适配器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'
关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.0446s