2017-04-06 78 views
2

我正在開發鬧鐘應用程序。 當它觸發警報時,它會通過禁用按鈕引發通知。 所以當我點擊禁用按鈕時,它應該停止鬧鐘鈴聲和鬧鐘。一起停止鬧鐘和鬧鐘鈴聲

所以當我點擊禁用按鈕它調用下面的方法。 它停止報警。 但我想知道這個鈴聲是否會在下一個日期同時存在,否則會消除鬧鐘?

public void dismissRingtone() { 
    // stop the alarm rigntone 
    Intent i = new Intent(this, RingtonePlayingService.class); 
    stopService(i); 

    // also dismiss the alarm to ring again or trigger again 
    AlarmManager aManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
    aManager.cancel(pendingIntent); 

    // Canceling the current notification 
    NotificationManager notificationManager = 
      (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE); 
    notificationManager.cancel(321); 
} 

回答

0

試試吧,它會取消將來的報警。

Intent intentAlarm = new Intent(this, AlarmReceiver.class); 
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
    // Set the alarm for a particular time. 

    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT); 

    try { 
     pendingIntent.cancel(); 
     alarmManager.cancel(pendingIntent); 
    } catch (Exception e) { 
     e.printStackTrace(); 

    } 
+0

在這裏你取消了掛起的意圖。這意味着廣播接收機.... – Shaon

+0

但在我的代碼中,我取消了當前的鬧鈴。但是,第二天的鬧鈴仍然活着嗎?我想知道 – Shaon

+0

廣播接收機+預定的待處理意圖將被取消,除非您不再計劃。 – Pehlaj