简体   繁体   中英

Android Permission BLUETOOTH Manifest error

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.

Any Ideas?

As an additional note, I imported this project in Android Studio from Intellij

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.

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

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.

Looks like it was a pretty straightforward solution. I was testing on Android Lollipop ( > maxSdkVersion ) hence the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM