Android 10-无法搜索蓝牙设备

时间:2020-04-03 02:47:12

标签: android search bluetooth

我正在使用Galaxy Note 10+,并且正在使用我编写的应用程序测试蓝牙功能。 当手机的Android版本为9时,蓝牙操作 (搜索,配对,连接等) 正常工作,但是自一个月前将版本升级到android 10以来, 我的应用无法找到附近的蓝牙设备。

在android OS菜单中,蓝牙搜索正在工作。 我的应用程序能够在android 9上搜索蓝牙设备,但无法在android 10上搜索。 android 10怎么了? 如何解决应用程序无法在Android 10上搜索蓝牙设备的问题? 请帮助我。

2 个答案:

答案 0 :(得分:0)

我有同样的问题。 我使用的是ACCESS_COARSE_LOCATION,但在新的android 10上却无法使用。 使用ACCESS_FINE_LOCATION使它按预期工作。

ActivityCompat.requestPermissions(
        this,
        arrayOf(
            Manifest.permission.BLUETOOTH,
            Manifest.permission.BLUETOOTH_ADMIN,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION
        ),
        PERMISSIONS_BLUETOOTH
)

答案 1 :(得分:-1)

在android 10中需要权限

蓝牙

BLUETOOTH_ADMIN

ACCESS_FINE_LOCATION

ACCESS_BACKGROUND_LOCATION //如果您的应用在后台运行

设备位置必须打开,并且您必须检查设备位置是否处于打开状态

LocationManager管理器=(LocationManager)getSystemService(Context.LOCATION_SERVICE);

if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));

}