简体   繁体   中英

Some Samsung phones with Android 6 or higher don't have android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS

My app needs to allow users to disable doze mode for my app, so for that the app needs to open android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS but I get android.content.ActivityNotFoundException when trying to open that intent on some Samsung phones like the Galaxy A5.

Is there an equivalent on those phones? What about other phones?

Thanks.

Edit: I just want to be clear, I'm trying to find what the actual setting screen is on Samsung Phones like the A5, not just how to open settings. I need to direct the users to the right location.

Edit: To clarify further, we have no found the setting on that Samsung phone to make isIgnoringBatteryOptimizations() return true . That is my main question, what setting needs to change on that phone for that to become true .

The Samsung Galaxy A5 ran on three OSs:

Android 6.0.1, Android 7.0, Android 8.0.0 ( GFX Bench )

The android.settings. IGNORE_BATTERY_OPTIMIZATION_SETTINGS activity was added in API 23. It was not removed afterwards. For some reason, this bug was never addressed by Samsung. The only solution is to bring the user to the system settings screen. See the following solution:

https://github.com/kontalk/androidclient/commit/be78119687940545d3613ae0d4280f4068125f6a

EDIT

After misunderstanding the question and with the clarification of the OP, I've added a potential solution to address which power setting needs to be accessed.

If you haven't already, make sure you are using android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Be sure that you add REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in your manifest prior to using this activity.

Activity Action: Ask the user to allow an app to ignore battery optimizations (that is, put them on the whitelist of apps shown by ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS). For an app to use this, it also must hold the Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission.

This should bring the user to the exact option necessary.

If you have one of these phones (maybe virtual from some online services) you can run the adb command to find the running activities, this way you can check the intent and maybe you are allowed to call it:

adb shell dumpsys activity activities

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM