Alarmmanager not working after phone reboot

北城余情 提交于 2019-11-28 12:42:10

all alarms are reset when phone restart ,So create a callback on reboot like this

public class BootCompletedIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
       ////// reset your alrarms here 
    }

}

}

ALSO ADD THIS TO YOUR MANIFEST TO REGISTER THE BROADCAST

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

Create a method say,

setMyalarm(){
     // here set the alarm as u need
}

now call this method setMyAlarm ,whenever and wherever u need to set that particular alarm,whether its on a button click or whether it on a reboot reciever

prefect ans by Ak9637 but didn't forgot to add permisttion of

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!