每天设置警报android

时间:2013-12-08 19:13:06

标签: android android-activity alarmmanager android-alarms alarms

我想让我的应用程序每天都设置警报,让我们说早上7点是用户的药片列表。到目前为止,当用户添加新药时,我一直这样做,我会直接设置闹钟,但我想让它仅为今天设置闹钟。我有一天能够使用xpath得到药片列表,并将药片列入清单。现在我在想是否可以通过某种隐藏的活动来保持运行或者设置日常药丸。如果有人能给我指示我应该寻找什么来解决这个问题,我们将不胜感激。

2 个答案:

答案 0 :(得分:0)

您应该使用:Alarm Manager。并将其放在Service中。另请阅读BroadcastReceiver

答案 1 :(得分:0)

我会为此提出一个想法。

  1. 使用Alarm的设置方法在早上7点安排第一个AlarmManager并注册BroadcastReceiver以便在早上7点执行使用相同的AlarmManager

  2. 早上7点,您的AlarmBroadcastReceiver将会执行。在您onReceive的{​​{1}}方法中再次设置BroadcastReceiverAlarm,使其成为自循环。

  3. 设置broadcastReceiver类的伪代码:

    BroadcastReceiver

    broadcastReceiver.class:

    Intent intent = new Intent(this, broadcastReceiver.class);
                    intent.putExtra("subject", subject);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
                            0, intent, PendingIntent.FLAG_ONE_SHOT);
    AlarmManager am= (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, "Your specific time", pendingIntent);
    
相关问题