Android Studio 蓝牙_连接、蓝牙_扫描缺少权限

5jvtdoz2  于 2022-12-23  发布在  Android
关注(0)|答案(2)|浏览(583)

enter image description here
“BLUETOOTH_CONNECT”和“BLUETOOTH_SCAN”似乎有问题。但我已经声明了。

`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" >

    <!-- 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" />

    <!-- Needed only if your app looks for Bluetooth devices.
         If your app doesn't use Bluetooth scan results to derive physical
         location information, you can strongly assert that your app
         doesn't derive physical location. -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

    <!-- Needed only if your app makes the device discoverable to Bluetooth
         devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

    <!-- Needed only if your app communicates with already-paired Bluetooth
         devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <!-- Needed only if your app uses Bluetooth scan results to derive physical location. -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- Include "neverForLocation" only if you can strongly assert that
             your app never derives physical location from Bluetooth scan results. -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
                     android:usesPermissionFlags="neverForLocation" />

    <!-- Not needed if you can strongly assert that your app never derives
         physical location from Bluetooth scan results and doesn't need location
         access for any other purpose. -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

</manifest>`

这是整个androidmanifest.xml.我不知道为什么有一个错误的代码.帮帮我.

5hcedyr0

5hcedyr01#

权限BLUETOOTH_CONNECT和BLUETOOTH_SCAN是所谓的运行时权限。在清单中声明它们是正确的,但您也需要在运行时请求它们。有关不同Android版本所需的所有权限的信息,请参见Bluetooth Permissions Guide
关于requesting permissions的指南详细解释了这些运行时权限所需的内容。

xam8gpfp

xam8gpfp2#

BLUETOOTH_CONNECTBLUETOOTH_SCANruntime permissions,因此,您不仅要在清单文件中声明这些权限,而且要在使用这些函数之前获得user's consent

相关问题