Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Permission: App crashes needing bluetooth permission

I was recently creating an app that uses bluetooth. The problem is my app crashes when ever I start the bluetooth service. Here's my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.petalappstudio.fit" >

<uses-permission android:name="ANDROID.PERMISSION.BLUETOOTH"/>
<uses-permission android:name="ANDROID.PERMISSION.BLUETOOTH_ADMIN"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name=".bluetoothManager"
        android:enabled="true"
        android:exported="true">
    </service>
</application>

Now as you can see I have added permission for bluetooth and bluetooth admin.

How ever my app crashes and in LOGCAT the error is

"java.lang.RuntimeException: Unable to start service " and is caused by
"java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10145 nor current process has android.permission.BLUETOOTH_ADMIN."

But I have added permission as you can see. Now why is this happening ?

like image 786
Vivek Sasidharan Avatar asked Oct 19 '22 10:10

Vivek Sasidharan


1 Answers

Try to add one more permission :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Refe. : Android Permission BLUETOOTH Manifest error

Note : also check device support Bluetooth feature or not using :

<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
like image 185
Haresh Chhelana Avatar answered Oct 22 '22 01:10

Haresh Chhelana