确实需要获取位置信息的,还是需要声明
Location
相关权限
-
Android 12 及以上,仅需配置
BLUETOOTH_SCAN
,并声明android:usesPermissionFlags="neverForLocation"
-
Android 9(API 28) 以上,需要声明
BLUETOOTH
,BLUETOOTH_ADMIN
及ACCESS_FINE_LOCATION
,参考官方文档 -
Android 9(API 28) 及以下,可以声明
ACCESS_COARSE_LOCATION
或者ACCESS_FINE_LOCATION
,推荐ACCESS_COARSE_LOCATION
综合起来,AndroidManifest文件为:
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30"/>
<!-- 安卓9及以下可以使用模糊定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="28"/>
<!-- 安卓10,11需要使用精准定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
tools:targetApi="q"
android:maxSdkVersion="30"/>
<!-- Needed only if your app looks for Bluetooth devices.
You must add an attribute to this permission, or declare the
ACCESS_FINE_LOCATION permission, depending on the results when you
check location usage in your app. -->
<!-- 安卓12及以上,不需要定位-->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
网友评论