开发者

AlarmManager not set from Bootreceiver

because of the fact that the AlarmManager is being cleared when the phone is booted, I created a BootReceiver class that should reset the alarms in this case. But even though the other code form this class is executed somehow the AlarmManager doesn't get set, so the AlarmReceiver class is never called. Here is part of my code from the BootReceiver class:

    Calenda开发者_Python百科r Od = Calendar.getInstance();
Od.set(yearOd, monthOd, dayOd, hourOd, minuteOd);

AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

                       int id= rebootCursor.getInt(ToDoDBAdapter.ID_COLUMN);

                       Intent i = new Intent(context, AlarmReceiver.class);
                       i.putExtra("alarm_message", "stavi_vibracii");
                       i.putExtra("doVreme",vremeDo);
                       i.putExtra("doDatum",dateDo);
                       PendingIntent sender = PendingIntent.getBroadcast(context, id, i, PendingIntent.FLAG_UPDATE_CURRENT);
                       am.set(AlarmManager.RTC_WAKEUP, Od.getTimeInMillis(), sender); 

I should note that I have registered the BootReceiver and AlarmManger in the Manifest file, and everyhting worked fine when setting the alarms within my app. If somebody had similar problems or have the answer to my question, please let me know.. Thank u


You may need to set a wake lock to keep the phone awake long enough to complete your tasks. See the information here:

https://github.com/commonsguy/cwac-wakeful

AND

http://www.androidguys.com/2009/04/02/wake-up-with-the-alarm/


A couple of things to check:

  • Your BootReceiver is implemented as a BroadcastReceiver
  • You've added the RECEIVE_BOOT_COMPLETED permission in your manifest

like this:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  • You've registered your boot receiver for the proper intent filter

like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜