1

我正在创建具有不同 ID 的多个警报,假设我创建了警报 1、2、3,我只想取消 2。你能指导我怎么做吗?我确实在 SO 上进行了搜索,但我没有找到任何关于在取消警报时是否必须将“相同的额外数据”添加到挂起的信息,所以我想我会问你,看看你会怎么做

这是我创建警报的方式

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
    broadcast_intent.putExtra("Tag", Object1);
    broadcast_intent.putExtra("Tag2", Object2);

   for(int i=1;i<=3;i++){       
       PendingIntent pendingIntent = PendingIntent.getBroadcast(this, i,  broadcast_intent, PendingIntent.FLAG_UPDATE_CURRENT);

       alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtTime, pendingIntent);

   } 

如何取消闹钟 2?

4

1 回答 1

0

它为我工作:-----

   buttonCancel.setOnClickListener(new Button.OnClickListener(){

  @Override
 public void onClick(View arg0) {

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
         pendingIntent = PendingIntent.getBroadcast(AndroidAlarmService.this, 0, broadcast_intent ,PendingIntent.FLAG_CANCEL_CURRENT);             
alarmManager.cancel(pendingIntent);

        // Tell the user about what we did.
        Toast.makeText(AndroidAlarmService.this, "Cancel!", Toast.LENGTH_LONG).show();


 }});
于 2012-11-08T05:15:04.877 回答