Android 10无法使用BLE蓝牙扫描 [英] Android 10 not working with BLE Bluetooth scanning

查看:1295
本文介绍了Android 10无法使用BLE蓝牙扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究BLE蓝牙扫描在除Android 10之外的所有设备上都可以使用.Android 10无法正常工作,任何人请回答有关版本10的问题以扫描BLE蓝牙

I am working on BLE Bluetooth scanning is working on all devices except the Android 10. Android 10 is not working, anyone please answer the question for the version 10 issues for scanning BLE Bluetooth

推荐答案

要使BLE扫描在定位到Android 10的Android应用上工作,您需要询问用户

To make BLE scanning work on Android apps targeting Android 10 you need to ask the user for

ACCESS_BACKGROUND_LOCATION

ACCESS_BACKGROUND_LOCATION

以及ACCESS_FINE_LOCATION,也不要忘记在清单中添加权限:

along with ACCESS_FINE_LOCATION and also don't forget to add the permission in the manifest:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

以下是原因:

Android 10(API级别29)引入了许多功能和行为更改,以更好地保护用户的隐私.这些更改扩展了用户对自己的数据及其提供给应用程序的功能的透明度和控制力.

Android 10 (API level 29) introduces a number of features and behavior changes to better protect users' privacy. These changes extend the transparency and control that users have over their data and the capabilities they give to apps.

简而言之,您的问题:

在后台访问设备位置需要权限

Access to device location in the background requires permission

为了支持用户对应用访问位置信息的控制权,Android 10引入了 ACCESS_BACKGROUND_LOCATION 权限.

To support the additional control that users have over an app's access to location information, Android 10 introduces the ACCESS_BACKGROUND_LOCATION permission.

ACCESS_FINE_LOCATION

Unlike the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions, the ACCESS_BACKGROUND_LOCATION permission only affects an app's access to location when it runs in the background. An app is considered to be accessing location in the background unless one of the following conditions is satisfied:

属于该应用程序的活动可见. 该应用程序正在运行已声明位置为前台服务类型的前台服务.

An activity belonging to the app is visible. The app is running a foreground service that has declared a foreground service type of location.

要在您的应用程序中声明服务的前台服务类型,请将应用程序的targetSdkVersion或compileSdkVersion设置为29或更高.详细了解前台服务如何才能继续需要位置访问权限的用户发起的操作.

To declare the foreground service type for a service in your app, set your app's targetSdkVersion or compileSdkVersion to 29 or higher. Learn more about how foreground services can continue user-initiated actions that require access to location.

希望这可以解决您的问题:)

Hope this fixes your problem :)

这篇关于Android 10无法使用BLE蓝牙扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆