java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission

a 夏天 提交于 2019-12-13 11:57:00

问题


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.


回答1:


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




回答2:


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.




回答3:


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.




回答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).




回答5:


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



来源:https://stackoverflow.com/questions/19974264/java-lang-securityexception-need-bluetooth-privileged-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!