嗨,我是新手Android开发我正在开发一个与notification
报警相关的应用程序,而我在特定时间设置报警,所有工作都完美正常并且报警正确,但报警notification
重复有些时候,我不重复它,我怎么能避免这个问题。
这是我的代码:
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("ti", name);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
final Calendar cal = Calendar.getInstance();
switch(Cun.valueOf(repeat)) {
case No:
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
break;
}
答案 0 :(得分:0)
警报首次通知后,使用以下方法取消:
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("ti", name);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel ( pendingIntent );