简体   繁体   中英

Bluetooth intent permission denied

I am trying to pass the intent mentioned below but i am getting the following exception below . Anyone have any idea about this????

Intent intent = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothProfile.EXTRA_STATE,BluetoothAdapter.STATE_CONNECTED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mdevice);
sendBroadcast(intent);

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED from pid=10459, uid=10126

您是否在清单中添加了权限?

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

ACTION_CONNECTION_STATE_CHANGED is a protected intent which can and should only be broadcast by Android. You cannot broadcast protected intents.

This is mainly to protect recievers of this intent from recieving spurious intents from apps that cannot change the state of Bluetooth headset.

Why do you want to send this intent when you have not changed the state?

Did you add

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

in your manifest ?

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