2011-10-17 51 views
0

我的工作日曆事件。如何取消重複鬧鐘設置爲每

當添加事件到日曆我創建使用報警經理

這是工作的罰款警告。

我要取消警報的特定事件而刪除事件。

我設置這樣的報警。

AlarmManager amgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE); 

Intent intent=new Intent(AmdAddEvent.this, RepeatingAlarmReceiver.class); 
intent.putExtra("time", mAlarmTime); 
PendingIntent pendingIntent=PendingIntent.getBroadcast(AmdAddEvent.this,(int) mAlarmTime,intent,PendingIntent.FLAG_CANCEL_CURRENT); 


amgr.setRepeating(AlarmManager.RTC_WAKEUP, mAlarmTime,AlarmManager.INTERVAL_DAY, pendingIntent); 

如何在刪除事件時取消提醒。

請幫我對此

由於提前

回答

0
amgr.cancel(Pending Intent); , 

,你可以用它來取消掛起的報警事件。

AlaramManager Cancel

0

如果你是編碼在另一個類刪除事件,那麼你需要用相同的ID重新創建一個意圖(在你的情況下,(int) mAlarmTime),然後就可以取消特定的報警意圖.else你可以使用alarmManager oject的cancel()。輸入以下代碼行刪除警報事件:

try 
{  
    Intent intent=new Intent(AmdAddEvent.this, RepeatingAlarmReceiver.class); 
    intent.putExtra("time", mAlarmTime); 
    PendingIntent pendingIntent=PendingIntent.getBroadcast(AmdAddEvent.this,(int) mAlarmTime,intent,PendingIntent.FLAG_CANCEL_CURRENT); 

    amgr.cancel(pendingIntent); 
} 
catch (Exception e) { 
    // TODO: handle exception 
} 
+0

我給出的代碼相同的線AMDDeleteEvent類,但它不工作仍警告即將eventhough我已經取消 – dhriti

+0

你檢查連接到每個報警管理者意圖ID報警?如果您使用多個警報事件,它必須是唯一的。 PendingIntent pendingIntent = PendingIntent.getBroadcast(AmdAddEvent.this,alarmIntentId,intent,PendingIntent.FLAG_CANCEL_CURRENT); – Hiral

+0

是的,確保你沒有寫出amgr.setRepeating ....在我給出的代碼行之後。相反,你必須使用amgr.cancel(的PendingIntent) – Hiral

0

請勿使用getBroadcast()方法,它將不起作用。

使用下面的代碼來創建一個警報,以創建活動:

pendingIntent = PendingIntent.getActivity(RemindingService.this, day, intent, PendingIntent.FLAG_UPDATE_CURRENT |PendingIntent.FLAG_ONE_SHOT); 

使用下面的代碼可隨時取消報警:

pendingIntent = PendingIntent.getActivity(RemindingService.this, id, intent, PendingIntent.FLAG_NO_CREATE|PendingIntent.FLAG_ONE_SHOT); 
if(pendingIntent != null) { 
alarmMgr.cancel(pendingIntent); 
    pendingIntent.cancel(); 
} 

這將測試和它運作良好。