在Androidmanifest.xml中开启BLUETOOTH_SCAN权限
时间: 2024-10-18 08:23:02 浏览: 30
Android权限列表permission说明.
在AndroidManifest.xml文件中添加蓝牙扫描权限,你需要在`<uses-permission>`标签内声明`<uses-feature>`以及`<permission-sdk>`。以下是具体的步骤:
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name">
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- Bluetooth LE (Low Energy) scanning requires a higher API level -->
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- For location-based scanning -->
<!-- If you want to receive advertisements from devices without pairing -->
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- Add this permission for Android 6.0 (API level 23) and above -->
<uses-permission android:name="android.permission.REQUEST_LOCATION_PERMISSION" android:maxSdkVersion="29" />
<application>
<!-- ... -->
<activity>
<!-- ... -->
<!-- Here's where you declare your activity requesting the scan permission -->
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<!-- You can also request location permissions if needed -->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
```
阅读全文