1

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.

casolorz
  • 8,486
  • 19
  • 93
  • 200

2 Answers2

0

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.

EMcCrary
  • 39
  • 7
  • But what is the setting they need to disable on the Samsung Galaxy A5? the one user I have with that phone continues on getting `false` for `isIgnoringBatteryOptimizations()` after changing every battery saving setting they could find. – casolorz Feb 04 '21 at 17:59
  • Sorry! I must have misunderstood the question. I'm updating my answer, but I'm still unsure because I'm not sure what you've implemented and what you haven't. – EMcCrary Feb 05 '21 at 17:29
  • Google has a very limited list of functions that an app must provide to get approved to use the actual battery optimization permission on the manifest, in fact, they'll suspend your app if you do that. So I can only use the stuff you do after your first `try/catch`, and I already do that. My problem is with users that would end up on the third `catch` on your code, in some cases it is very hard to find the right location for that setting. On the `A5` in particular we still haven't found it. – casolorz Feb 06 '21 at 18:09
0

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

Ultimo_m
  • 4,724
  • 4
  • 38
  • 60
  • Our problem is that we haven't found the setting. Even after flipping every setting we have found, `isIgnoringBatteryOptimizations()` continues on being false. – casolorz Feb 10 '21 at 15:51
  • @casolorz find an app that does what you want (or uses that feature) and decompile it to check how they do it, maybe you need to check samsung apps installed on that phone – Ultimo_m Feb 10 '21 at 17:58