问题
- Are there callbacks on doze mode (on Doze first/second level, on start/end of maintenance window)?
- Is there a way to workaround Doze mode that is not dependent on the user approval?
- In previous versions (Android M and smaller) I used Android Service and partial wake lock to download and process data while the application was in background. Is there a way to download and process data in the background when Android N gets into Doze Mode?
回答1:
Are there callbacks on doze mode (on Doze first/second level, on start/end of maintenance window)?
If you have a running process, you can register a receiver for the ACTION_DEVICE_IDLE_MODE_CHANGED and ACTION_POWER_SAVE_MODE_CHANGED broadcasts. The former should correspond to Doze mode.
Is there a way to workaround Doze mode that is not dependent on the user approval?
I do not know what "workaround Doze mode" means. You can use the ...AndAllowWhileIdle()
methods on AlarmManager
, though I had mixed results. You can use GCM (or FCM nowadays). See the documentation.
In previous versions (Android M and smaller) I used Android Service and partial wake lock to download and process data while the application was in background.
Your partial wake lock should be revoked in Doze mode on Android 6.0 (a.k.a., M). Similarly, you should not have Internet access in Doze mode on Android 6.0.
Is there a way to download and process data in the background when Android N gets into Doze Mode?
For the full Doze mode, Android N does not appear to change things. For the partial Doze mode that Android N introduces, your partial wake lock should work, though I am uncertain about the network access.
回答2:
- In previous versions (Android M and smaller) I used Android Service and partial wake lock to download and process data while the application was in background. Is there a way to download and process data in the background when Android N gets into Doze Mode?
When device enters Doze mode most functions stop due in fact de CPU stops, then the way should be to avoid enter Doze mode :
The thing that works for me is to use a foreground service, that's a Service that calls startForeground() (1) and shows a non dismissable notification, then the partial wake lock is respected and the device doesn't enter Doze Mode.
(1) beginning at Android 8 the method to start a foreground service has changed Android O - Old start foreground service still working?
来源:https://stackoverflow.com/questions/37725096/android-n-doze-mode-how-to-keep-background-download-and-processing