bartolja
bartolja

Reputation: 497

Starting foreground service in doze mode

I'm developing an app which connects to a special device via wifi. I need to make status updates in a short interval, resp. keep the status of my special device in the app up to date. FCM is not an option. My idea is to give the user two options: Fast updates using a foreground service or "slow" updates using a periodical update mechanism to save battery.

My question is about the second option. The interval should be around five minutes. Using JobScheduler therefore is not possible. But even using the AlarmManager seems not to be an option because I'm not able to get network access during the doze maintenance windows.

I thought about using a WakefulBroadcastReceiver to receive the Intent by the AlarmManager, require a WakeLock and turn my long running Service into foreground by calling startForeground(). But it seems that the startForeground() method has no effect on the Service as long as the device stays in doze mode.

I read many pages about doze and services but have no clue how to solve my problem... Does anyone got an idea?

Upvotes: 3

Views: 1822

Answers (2)

iClaude
iClaude

Reputation: 163

You can use setAlarmClock, but it is not recommended for your purposes. Instead you can use setExactAndAllowWhileIdle with manual re-programming with an interval of 15 minutes. Best way: GCM.

Upvotes: 0

A. Shevchuk
A. Shevchuk

Reputation: 2169

you should use GcmTaskService. You can schedule some interval for your operations and it would work fine even in doze mode, check more information by link

Upvotes: 2

Related Questions