Android 权限蓝牙清单错误
Android Permission BLUETOOTH Manifest error
以下是 AndroidManifest.xml 简单蓝牙配对 Android 项目
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetoothglassend"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="19" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="19" />
<uses-permission
android:name="android.permission.BLUETOOTH_PRIVILEGED"
android:maxSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
虽然不是必需的,但我已经为我能找到的所有 BLUETOOTH 参数添加了权限。然而,我得到这个错误:
java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10145 nor current process has android.permission.BLUETOOTH.
有什么想法吗?
作为附加说明,我从 Intellij
在 Android Studio 中导入了这个项目
看起来这是一个非常简单的解决方案。我正在测试 Android Lollipop ( > maxSdkVersion ) 因此出现错误。
maxSdkVersion 属性版本用于告知应向您的应用授予此权限的最高 API 级别。如果从某个 API 级别开始不再需要您的应用所需的权限,则设置此属性很有用。
例如,从 Android 4.4(API 级别 19)开始,当您的应用想要写入其在外部存储上拥有自己的特定于应用程序的目录(由 getExternalFilesDir() 提供的目录)。但是,API 18 级及以下需要权限。因此,您可以声明此权限只需要达到 API 级别 18,声明如下:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
这样,从 API 级别 19 开始,系统将不再授予您的应用 WRITE_EXTERNAL_STORAGE 权限。
所以错误是即使棒棒糖也需要您请求访问蓝牙的权限。
以下是 AndroidManifest.xml 简单蓝牙配对 Android 项目
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetoothglassend"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="19" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="19" />
<uses-permission
android:name="android.permission.BLUETOOTH_PRIVILEGED"
android:maxSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
虽然不是必需的,但我已经为我能找到的所有 BLUETOOTH 参数添加了权限。然而,我得到这个错误:
java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10145 nor current process has android.permission.BLUETOOTH.
有什么想法吗?
作为附加说明,我从 Intellij
在 Android Studio 中导入了这个项目看起来这是一个非常简单的解决方案。我正在测试 Android Lollipop ( > maxSdkVersion ) 因此出现错误。
maxSdkVersion 属性版本用于告知应向您的应用授予此权限的最高 API 级别。如果从某个 API 级别开始不再需要您的应用所需的权限,则设置此属性很有用。
例如,从 Android 4.4(API 级别 19)开始,当您的应用想要写入其在外部存储上拥有自己的特定于应用程序的目录(由 getExternalFilesDir() 提供的目录)。但是,API 18 级及以下需要权限。因此,您可以声明此权限只需要达到 API 级别 18,声明如下:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
这样,从 API 级别 19 开始,系统将不再授予您的应用 WRITE_EXTERNAL_STORAGE 权限。
所以错误是即使棒棒糖也需要您请求访问蓝牙的权限。