17

Has anyone meet the same problem as the following error message shows when calling bluetoothDeive.createBond() method with android 4.4 api?

java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission

Note: BLUETOOTH_ADMIN permission is already included in AndroidManifest file.

Falko
  • 17,076
  • 13
  • 60
  • 105
user2822074
  • 171
  • 1
  • 1
  • 4

5 Answers5

34

Got the exact error message.

Took me an hour to realize that the bluetooth on the phone is not enabled. After turning it on, it works as expected.

Dino Tw
  • 3,167
  • 4
  • 34
  • 48
  • 2
    I mean come on! Thank you! – Yokich May 02 '18 at 12:39
  • 2
    So glad I read this - definitely saved me an hour! What a strange error to throw when Bluetooth is off, it has nothing to do with permissions... I guess the system tries to turn Bluetooth on but can't? Weird. – Troy Stopera May 31 '19 at 19:42
  • 1
    I refused to believe that that stack trace was due to my Bluetooth being off until I read your answer... I was like ... "surely cant be as stupid as that..." – electrocrat Feb 20 '20 at 04:31
  • 1
    I can't believe this was the problem!!! I turned my bluetooth off and spent about an hour scratching my head on runtime permissions haha – Harry Luu Dec 02 '22 at 07:48
21

You can't use this permission if your app is a third party app (non-system app). To learn more, see Android API: BLUETOOTH_PRIVILEGED

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
wsgh
  • 225
  • 2
  • 6
1

I run on this error, and only I can say, you need to install your app as a system privileged app, to go to system folder and try to copy app to the app folder or priv_app folder. On my Android platform, when I made folder inside priv_app folder for my app and copied my apk to it and restarted Android, everything worked OK. I my case I added in manifest all this permissions at the beginning, but it worked only after this step above.

LadyG
  • 11
  • 1
-4

try this in your manifest

    <user-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

notice the user not uses-permission on the first line. Until I switched that, For some reason I kept getting

java.lang.SecurityException: Need BLUETOOTH_ADMIN permission

MrBoutte'
  • 349
  • 4
  • 14
-4

Try this:

1) remove "android.permission.BLUETOOTH_PRIVILEGED" from your permissions.
2) remove "android.permission.BLUETOOTH".
3) add "android.permission.BLUETOOTH_ADMIN" and just that.

The reference says that is the only permission needed.https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createBond()

EDIT: if you already included "bluetooth_admin", maybe its a platform problem.They may have not supported that functionality earlier. Maybe you should target a higher min-sdk-platform , Im using Android 20 as the minimum (but never tried that function).

Gabo Alvarez
  • 139
  • 8