问题描述
以下是AndroidManifest.xml中的一个简单的蓝牙配对的Android项目
Following is the AndroidManifest.xml for a Simple Bluetooth pairing Android Project
<?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>
虽然不是必需的,我已经添加权限的所有蓝牙参数我能找到。然而,我得到这个错误:
Although not required, I've added permissions for all BLUETOOTH parameters I can find. Yet, I get this error :
java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10145 nor current process has android.permission.BLUETOOTH.
任何想法?
作为一个额外的说明,我进口这个项目Android Studio中的IntelliJ从
As an additional note, I imported this project in Android Studio from Intellij
推荐答案
该maxSdkVersion属性的版本是告诉在此权限应授予您的应用程序的最高API级别。如果您的应用要求许可,不再需要在一定的API级别开始设定这个属性是非常有用的。
The maxSdkVersion attribute version is for telling the highest API level at which this permission should be granted to your app. Setting this attribute is useful if the permission your app requires is no longer needed beginning at a certain API level.
例如,采用Android 4.4(API级别19)开始,它不再需要时,您的应用程序要写入外部存储自己的应用程序特定的目录(由getExternalFilesDir提供的目录,你的应用程序请求WRITE_EXTERNAL_STORAGE许可())。然而,需要API级别18和较低的权限。所以,你可以声明此权限只需要一个声明,如这份长达API级别18:
For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()). However, the permission is required for API level 18 and lower. So you can declare that this permission is needed only up to API level 18 with a declaration such as this:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
此方式,用API 19级开始,系统将不再授予您的应用程序的权限WRITE_EXTERNAL_STORAGE
This way, beginning with API level 19, the system will no longer grant your app the WRITE_EXTERNAL_STORAGE permission.
所以,错误是,即使棒棒糖需要你请求允许访问蓝牙。
So the error was that even lollipop needs you to ask permission for accessing bluetooth.
这篇关于Android的权限BLUETOOTH明显错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!