2012-12-10 2 views
2

AlarmManager 예를 들어 휴대 전화가 잠긴 경우 브로드 캐스트 수신기가 시작되지 않습니다. 검색하고 많은 솔루션을 시도하지만 아무도 작동하지 않습니다 :전화가 잠겨있을 때 AlarmManager가 작동하지 않음

AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
     Intent i = new Intent(context, OnAlarmReceiver.class); 
     PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); 

     mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
         SystemClock.elapsedRealtime()+60000, 
         PERIOD, 
         pi); 

OnAlarmReceiver 결코 해고되지 않습니다!

@Override 
    public void onReceive(Context context, Intent intent) { 
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
     PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); 
     wl.acquire(); 
// code 
wl.release(); 
} 

을뿐만 아니라, 작동하지 않는 :

또한 WakeLock으로 시도합니다. 왜?

+0

'이 매니페스트 파일에 추가 되었습니까? –

+0

이 매니페스트에 추가되었습니다 – senzacionale

+1

http://stackoverflow.com/a/6865323/1339473 @senzacionale이 문제가 해결 될 것이라고 생각합니다 – QuokMoon

답변

1

but OnAlarmReceiver is never fired!

해야합니다. Here is a sample project은 화면이 꺼져 있고 휴대 전화가 잠겨있을 때 완벽하게 작동하는 AlarmManager과 비슷한 사용법을 보여줍니다. 내 샘플에서 "실제 작업"은 BroadcastReceiver을 사용하여 WakefulIntentService으로 수행되므로 BroadcastReceiver이 확실히 제어 할 수 있습니다.

+0

고맙습니다. 예를 들어 OnBootReceiver를 OnScreenChangeReceiver로 변경하지만 나중에 OnAlarmReceiver가 호출되지 않습니다. 다음과 같이 OnScreenReceiver를 실행합니다. 'final IntentFilter intentScreenfilter = new IntentFilter (Intent.ACTION_SCREEN_ON); intentScreenfilter.addAction (Intent.ACTION_SCREEN_OFF); screenReceiver = 새로운 OnScreenReceiver(); // 서비스가 브로드 캐스트를 수신하도록 수신기를 등록하십시오. registerReceiver (screenReceiver, intentScreenfilter); ' – senzacionale

+0

및 로그에서 다음을 볼 수 있습니다 :'12-10 16 : 36 : 00.000 : E/AlarmManagerService (1990) : android_server_AlarmManagerService_set to type = 3, 1195102.441000000 12-10 16 : 36 : 00.015 : D/KeyguardUpdateMonitor (1990) : 수신 브로드 캐스트 android.intent.action.TIME_TICK 12-10 16 : 36 : 00.020 : D/KeyguardUpdateMonitor (1990) : D/STATUSBAR-Clock (2107) : updateClock : 16 : 36 D/STATUSBAR-DateView (2107) : D/STATUSBAR-Clock (2107) : ACTIVE_TIME_TICK 12-10 16 : 36 : 00.045 : updateClock : D/DigitalClock (23824) : DigitalClockAppWidgetService. action : android.intent.action.TIME_TICK' – senzacionale

+0

그리고 예제에서 AlarmManager를 중지하는 방법은 무엇입니까? – senzacionale

관련 문제