Cihazımı, bir Hizmete ateş açan bir WakefulBroadcastReceiver kullanarak uyandırmaya gidiyorum. Servis bir Etkinlik başlatır ve sonunda işi bitirmek için WakefulBroadcastReceiver'a bildirir. Kayıt dosyası yaptım ve hiçbir şey görmedim. Cihazın kilidini açtığımda, birkaç saniye sonra aktivite başlıyor. Alarmı ayarladığımda neden çalışmıyor?Neden WakefulBroadcastReceiver cihazımı derin uykudan uyandırmıyor?
Bildirim, BroadcastReceiver ve Service declaration ve WAKE_LOCK iznini içerir. İşte
WakefulBroadcastReceiver geçerli:public class AlarmBroadcastReceiver extends WakefulBroadcastReceiver {
public AlarmBroadcastReceiver() {
Logging.logToFile("Construct broadcast receiver");
}
@Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, AlarmService.class);
startWakefulService(context, service);
Logging.logToFile("Started wakeful broadcast receiver");
}
}
Ve burada Hizmet sınıftır:
public class AlarmService extends IntentService {
public AlarmService() {
super("AlarmService");
Logging.logToFile("Started intent service");
}
@Override
protected void onHandleIntent(Intent intent) {
Logging.logToFile("Handle intent service");
Intent service = new Intent(this, WakeUpActivity.class);
service.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(service);
AlarmBroadcastReceiver.completeWakefulIntent(intent);
}
@Override
public void onDestroy() {
super.onDestroy();
Logging.logToFile("Destroy intent service");
}
}
Ve işte benim günlük geçerli:
At 2016-04-01 23:14: Alarm set at 23:20
At 2016-04-01 23:23: Construct broadcast receiver
At 2016-04-01 23:23: Started wakeful broadcast receiver
At 2016-04-01 23:23: Started intent service
At 2016-04-01 23:23: Handle intent service
At 2016-04-01 23:23: Started WakeActivity
At 2016-04-01 23:23: Destroy intent service
At 2016-04-01 23:25: Alarm set at 23:30
At 2016-04-01 23:33: Construct broadcast receiver
At 2016-04-01 23:33: Started wakeful broadcast receiver
At 2016-04-01 23:33: Started intent service
At 2016-04-01 23:33: Handle intent service
At 2016-04-01 23:33: Destroy intent service
At 2016-04-01 23:33: Started WakeActivity
At 2016-04-01 23:34: Alarm set at 23:40
At 2016-04-01 23:42: Construct broadcast receiver
At 2016-04-01 23:42: Started wakeful broadcast receiver
At 2016-04-01 23:42: Started intent service
At 2016-04-01 23:42: Handle intent service
At 2016-04-01 23:42: Destroy intent service
At 2016-04-01 23:42: Started WakeActivity
At 2016-04-01 23:43: Started WakeActivity
At 2016-04-01 23:44: Alarm set at 23:49
At 2016-04-02 00:02: Construct broadcast receiver
At 2016-04-02 00:02: Started wakeful broadcast receiver
At 2016-04-02 00:02: Started intent service
At 2016-04-02 00:02: Handle intent service
At 2016-04-02 00:02: Started WakeActivity
At 2016-04-02 00:02: Destroy intent service
Düzenleme: Ve ayarlamak böyle mi alarm:
Intent intent = new Intent(SmartClockActivity.this, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(SmartClockActivity.this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
Lütfen –
@DavidMedenjak alarmını nasıl ayarlayacağınızı belirtin. –