首页 > 解决方案 > 在 Android 10 中获取蓝牙本地 mac 地址

问题描述

由于安全原因,bluetoothAdapter.getAddress() 从 Android Marshmallow 返回 02:00:00:00:00:00。我尝试从 android.provider.Settings.Secure 获取但仍然失败。那么有没有办法获取本地蓝牙mac地址呢?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bluetooth_address = android.provider.Settings.Secure.getString(getContentResolver(), "bluetooth_address");
    address = findViewById(R.id.address1);
    address.setText(bluetooth_address);
}

“我希望 textView 会设置为 6B:3E:CB:2E:C4:C7,但实际输出为空。”</p>

标签: androidandroid-studioandroid-bluetooth

解决方案


推荐阅读