OiO.lk Blog Android Permission Denial: android.bluetooth.device.action.ACL_DISCONNECTED
Android

Permission Denial: android.bluetooth.device.action.ACL_DISCONNECTED


I’m getting below error while sending a broadcast event.

Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.bluetooth.device.action.ACL_DISCONNECTED

I’ve already provided all the required permissions in the manifest too but unable to fix it.

 <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" tools:ignore="ProtectedPermissions" />

    <uses-feature android:name="android.hardware.bluetooth" android:required="false" />
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />

I’m registering in activity as:

private fun setBluetoothReceiver() {
        val filter = IntentFilter(BluetoothDevice.ACTION_FOUND)
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
        filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED)
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED)
        registerReceiver(bluetoothReceiver, filter)
    }

And sending Broadcast from the onReceive function of the Broadcast Receiver as:

val local = Intent()
                    local.setAction(BluetoothDevice.ACTION_ACL_DISCONNECTED)
                    local.putExtra("number", device.name)
                    if (context != null) {
                        context.sendBroadcast(local)
                    }

Please help me out to know why this is happening?



You need to sign in to view this answers

Exit mobile version