3

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)
    {
        

    }
}
Hannan Shahid
  • 50
  • 2
  • 8

2 Answers2

2

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()))

anshul
  • 982
  • 1
  • 11
  • 33
  • 2
    brother all tried but not working with android 11 ...all other android versions work fine – Hannan Shahid Dec 14 '20 at 12:52
  • @HannanShahid Did you try this https://stackoverflow.com/questions/60699244/boot-completed-not-working-on-android-10-q-api-level-29 – anshul Dec 14 '20 at 14:41
-2

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