Home » Android » How to set permissions for Android Bluetooth

How to set permissions for Android Bluetooth

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m new to Android development. I’m trying to get a simple HelloWorld app going on my (rooted) phone – and the app is trying to enable Bluetooth.

I’ve set the Bluetooth permissions in my manifest is as follows, but I’m getting a Permission Denial exception when I try to run the application on my phone via Eclipse:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.helloandroid"
          android:versionCode="1"
          android:versionName="1.0">      
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:permission="android.permission.BLUETOOTH_ADMIN">
            <activity android:name=".HelloAndroid"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-sdk android:targetSdkVersion="7" android:minSdkVersion="5"></uses-sdk>
</manifest>

Is there something obvious I’m missing?

How to&Answers:

I’m not quite sure what the problem was here.

All I can say is that I reinstalled Eclipse and its plugins and now everything is working fine. Thanks for your help Mayra – I’ll up-mark your answer because of your helpful and friendly approach.

Answer:

The answer about what to include in your manifest.xml for bluetooth activity includes

<uses-feature android:name="android.hardware.bluetooth" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

The first three are of greater priority and as I’m sure you’re aware there are different cases when each dependency may be required. Hope it helps with your setup!

Answer:

The element types in the manifest are ordered. I think the uses-permission needs to be first under the tag.