Reputation:
I used Alarm Manager to trigger every 5 seconds and it works fine. But the problem is the phone didn't go into sleep mode and I can't see the gap from the collected data using alarm manager. Can anyone help me how to check if the phone goes into sleep correctly or not?
here is my code
Intent alarmIntent = new Intent(this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
public void startAlarm() {
manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
int interval = 5000;
manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
Toast.makeText(this, "Alarm Set", Toast.LENGTH_SHORT).show();
}
Upvotes: 1
Views: 108
Reputation: 6392
By using AlarmManager
you ensure that your app will be waken by the system even if the phone is sleep and your activity/service is in the background.
But this does not mean your app (or any other app) have the ability to force the device into Doze mode.
In order to validate that your app works in Doze as expected use this command to force the device into Doze mode:
$ adb shell dumpsys deviceidle force-idle
Additional Info
this method:
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP...
WILL NOT wakeup the device if it's in Doze mode, only after the device will get out from the Doze mode.
To ensure your app will work in Doze use this command:
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP...
Upvotes: 1