Search code examples
androidandroid-permissionsandroid-broadcastreceiver

Permission Denial for Broadcast Receiver


Im trying to set up a receiver to relaunch my applications alarms/notifications once the phone reboots.

Im getting stuck with a permission denial error:

W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.closedbracket.trackit/.BootBroadcastReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)

I've looked at a lot of SO questions simillar to this but haven't found a solution yet.

This is my manifest:

    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    <uses-permission android:name="com.android.permission.RECEIVE_BOOT_COMPLETED" />
<application
....
<receiver
            android:name="com.closedbracket.trackit.BootBroadcastReceiver"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>
</application>

And this is my BootBroadcastReceiver:

public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.i("BootBroadcastReceiver", "Received");
}}

I am testing this with the Android Stuido Emulator by doing the restart functionality. I then check the logs and see the Permission Denial line in reference to my broadcast receiver and don't see my log of the onReceive method.

Literally tried everything I could, even changing the manifest's android:enable/export values, and adding the permission inside of it. Made no difference.

If anyone has any ideas, please let me know. Thank you.


Solution

  • You have the permission com.android.permission.RECEIVE_BOOT_COMPLETED, but as the error message says, you are supposed to have android.permission.RECEIVE_BOOT_COMPLETED without the com. at the beginning.