how to run Boot Broadcast Receiver on android 11

Viewed 3075

i am actually working on alarm app that set alarm ans store alarm data into room database,i want to Re Schedule my alarms after the phone reboot. all work fine but its not working on android 11.In android 11 the boot reciver not trigger and in other devices boot receiver trigger and set all the alarm stored in database

thanks

i am using this code

 override fun onReceive(context: Context?, intent: Intent?) {
    if (Intent.ACTION_BOOT_COMPLETED == intent?.action)
    {
        

    }
}
2 Answers

I hope you have set the below permission

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

and added the intent filter for your receiver like below

 <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>

If the above things are in place. Then try the below things as well

  1. Click on the app after installing your app as until your app is enabled you won't be able to receive BOOT COMPLETE action

  2. Check the condition like below

    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))

In Android 11 you need to open your app after restarting to receive Boot_Complete_receiver

Related