【发布时间】:2015-04-06 17:57:57
【问题描述】:
我可以为每 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 小时重复一次。 我的研究表明我将不得不菊花链警报所以如果一个响起我必须设置为第二天。你能帮我理解如何做到这一点吗?如何在触发警报并处理我的待处理意图时重置警报,因为我的待处理意图正在调用 A 服务,而我不知道如何在服务中设置警报。
这是我的服务:
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);
}}
【问题讨论】:
标签: android notifications android-service alarmmanager reminders