2017-03-10 2 views
-2

Android 기본으로 하나의 응용 프로그램을 만들었습니다. 나는 매 1 분 트랙 데이터를 얻기 위해 AlarmManager를 사용하고있다.1 분마다 알람을 설정하는 방법, 안드로이드에서만 똑같이 말하는가?

AlarmManager alarmManager=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); 

Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class); 

PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); 
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),100000,pendingIntent); 

하지만 오늘 오후 12시와 같은 특정 시간에 중지해야합니다. 또는 내가 원하는 모든 시간.

다른 AlarmManager 서비스를 작성하면 어떻게됩니까? 아니면 다른 옵션이 있습니까?

+1

사용 서비스가. 이를 위해 고정 된 ID를 보류중인 의도로 설정해야합니다. 및 서비스 취소에서 보류중인 의도 –

+0

고정 된 ID를 보류중인 의도로 설정하는 방법. 다른 AlarmManger 서비스에서 설정하고 싶다면 가능합니까? –

+1

이 줄, PendingIntent pendingIntent = PendingIntent.getBroadcast (getApplicationContext(), "ID_OF_PENDING", 의도, 0); . 이제 마지막 행을 제외하고 위의 행을 작성하고 alarmManager.cancel (pendingIntent); 동일한 ID로 –

답변

1

그냥 알람에 의해 발사 서비스 체크인 현재 초기 특정 시간보다 시간이 진행중인 알람을 취소

if (isTimeExpired) { 
    AlarmManager alarmManager=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); 
    Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);  
    alarmManager.cancel(pendingIntent); 
} 
+0

예. 작동합니다. 고마워 친구.. –

관련 문제