REQUEST_IGNORE_BATTERY_OPTIMIZATIONS how to do it right

前端 未结 2 1270
再見小時候
再見小時候 2020-12-28 16:52

I have IntentService task in foreground mode, but in Android M+ the task stops in Doze mode. I read Google banned if the app uses intent to set themselves in wh

2条回答
  •  再見小時候
    2020-12-28 17:21

    Be aware of using Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent for the activity, this does not work on all phones and you will get a android.content.ActivityNotFoundException. In particular it does not work on Samsung phones running Android 6. The only combination that I have found works on these phones is to declare the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in the manifest, then launch an activity with intent Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. I.e. the combination that is not liked by Google.

提交回复
热议问题