2013-12-17 5 views
0

안녕 난 여기에 알람을하고 난 예 또는 일주일 동안 매일 같은 시간 후에이를 취소 할 수있는 방법을 원하는 ,,, 사전에 감사 ,,일정 기간 후에 어떻게 경보를 취소 할 수 있습니까? | 안드로이드

am = (AlarmManager)parent.getContext().getSystemService(Context.ALARM_SERVICE); 

    //the title and the description of the notification 



    Intent alarmintent = new Intent(parent.getContext(), Alarm_Receiver.class); 
    alarmintent.putExtra("title",titlePills + dea22); 
     alarmintent.putExtra("note",dea22); 
    alarmintent.putExtra("NOTIFICATION_ID",String.valueOf(CountMultipleAlarm)); 
    //HELLO_ID is a static variable that must be initialized at the BEGINNING OF CLASS with 1; 

     //example:protected static int HELLO_ID =1; 
     PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm, 
            alarmintent,0); 

     //VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... this will send correct extra's informations to 
     //AlarmReceiver Class 
     // Get the AlarmManager service 
     am.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), 11000, sender); 
            intentArray.add(sender); 
+0

원래 알람을 취소하는 것이 다른 알람을 설정합니까? – PearsonArtPhoto

+0

코드가 있으십니까? 나는 시간주기와 취소 기능을 어떻게 해야할지 모르겠다 –

+0

내 대답은 당신이 취소 알람 수신기에 넣어해야 코드를 보여줍니다. 이미 알람을 설정 했으니 잠깐 설정할 수 있다고 가정 할 것입니다. 거기에 포함 된 코드를 플로팅하십시오 (이미 약간의 여분 비트가 필요합니다). 가기. – PearsonArtPhoto

답변

0

을 시도, 그래서 당신은 그것을 할 방법을 알고있다. 열쇠는 두 번째 경보를 설정하는 것입니다.이 경보의 목적은 원래의 경보를 종료하는 것입니다. 어려운 부분은 취소 할 원래 경고를 찾는 것이지만 cancel pending intent을 사용하여 두 번째 경고에서 첫 번째 경고를 취소하기 위해이 코드를 실행할 수 있습니다. 이 코드는 Android docs에서 지정한대로 같은 클래스의 모든 알람을 취소합니다. 따라서 인 텐트를 생성하여 AlarmManager에 전달하면 알람을 취소 할 수 있습니다.

Intent alarmintent = new Intent(parent.getContext(), Alarm_Receiver.class); 
PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm, 
           alarmintent,0); 
am.cancel(sender); 
+0

감사하지만 어디에서 내 기간을 결정합니까? –

+0

오직 알람을 설정하는 데 걸리는 시간을 결정할 수 있습니다 ... – PearsonArtPhoto

1

두 번째 알람 설정 첫 번째 경보를 취소합니다.

+0

이것은 코멘트 여야합니다. 이것은 대답으로 받아 들여지지 않아야합니다. – Piyush

+0

코드가 있으십니까? 나는 당신의 솔루션과 함께 전체 시간을 실행 해야하는 기간을 –

1

는 이미 한 번 알람을 설정 한

final PendingIntent sender = PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm, 
            alarmintent,0); 
int someTime=1000; 

new Handler().postDelayed(new Runnable() 
{ 
    public void run() 
    { 
    am.cancel(sender); 
    } 
}, someTime); 
+2

취소 기능을 어떻게 해야할지 모르겠다. 두 번째 알람을 시작하는 것이 더 좋습니다 – Frame91

관련 문제