2017-04-06 1 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

관련 문제