0
我能設置AlarmManager報警被觸發每24小時多次:如何設置AlarmManager對於必須重複通知了一天的日常
Calendar c= Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY,holder.hours);
c.set(Calendar.MINUTE,holder.min);
Intent in=new Intent(Reminder_entry.this,Notificationservice.class);
in.putExtra("name",holder.name);
PendingIntent pi=PendingIntent.getService(Reminder_entry.this, holder.pi, in,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManageram=AlarmManager)Reminder_entry.this.getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), 1000 * 60 * 60 *24,pi);
,但我不能把它所以它可以每天每6小時重複講話。 我的研究表明,我將不得不雛菊鏈警報器,所以如果一個熄滅,我必須爲第二天設置。你能幫助我理解如何做到這一點嗎?我怎樣才能重置警報,當它被觸發,我的待決意圖處理,因爲我的未決意圖調用服務,我不知道如何設置服務中的警報。
這是我的服務:
public class Notificationservice extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String name=intent.getStringExtra("name");
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent i=new Intent(Notificationservice.this,Notification_landing.class);
PendingIntent pi=PendingIntent.getActivity(Notificationservice.this, 0, i,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b= new NotificationCompat.Builder(Notificationservice.this);
b.setAutoCancel(true).setContentTitle(name).setContentText("time to take "+name).setSmallIcon(R.drawable.ic_launcher).setSound(soundUri);
b.setContentIntent(pi);
Notification n=b.build();
NotificationManager nm=(NotificationManager)Notificationservice.this.getSystemService(NOTIFICATION_SERVICE);
nm.notify(1,n);
return super.onStartCommand(intent, flags, startId);
}}
那麼當你以前的報警觸發你的設置這個新的報警?我的意思是我的應用程序是一種藥物提醒,因此用戶可能每隔5天每隔5小時就要吃藥。想象今天是星期一,所以在4次重複之後,我必須在48小時後每5小時重置鬧鐘。 – 2015-04-06 08:53:58
是的,在前一次發射後設置新的警報。 因此,對於您的情況,您可能需要添加一些額外的邏輯來確定是否爲另外2天或5小時的警報。例如也許有一個警報,接着是每5小時4次,然後是48小時後再次發出警報(然後重複週期)。 – aoemerson 2015-04-06 09:35:28
終於破解了,非常感謝你的幫助。如果我存儲唯一的待處理意圖,如果用戶選擇刪除藥物,是否可用於取消警報? – 2015-04-06 17:23:05