2

I implemented ignore battery optimization functionality programmatically. I found lots of questions and answers but i want to know that the IGNORE_BATTERY_OPTIMIZATIONS is works only for pure android or is there any other cases?

I have couple of devices as below listed :

  • Moto g4 (7.0)
  • Moto g play (6.0)
  • Samsung galaxy note 4(6.0)
  • Mi note 4 (6.0)
  • Lenovo Tab(6.0)
  • Honor (6.0)

It works proper in Moto device.

In Moto we able to get pop up and if we accept permission then it works well.

It work 50% correct in Lenovo tab & Honor devices.

  • In Lenovo tab when the Permission pop up appears and if we accept the permission then the application added but when we change settings manually it's not working.
  • Well while in Honor devices when we got permission popup and accept the permission after that we open setting and check the app status its listed in don't allow battery optimization app but the state of the application is "Allow battery optimization". After that when we allow it manually it will work.

In MI and Samsung devices it's not working anymore.

well The Mi Devices are exceptional cases as they have their customized architecture, so we are not concerning MI devices.

for Samsung note 4 there is a special case as below :

After installing app we got the permission pop up and accept the permission. After that we check it in setting, but the app is not listed in "don't allow battery optimization" app list. (Note: When device will reboot the app added in don't allow battery optimization)

Here is Code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        msPackageName = getPackageName();
        moPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        Log.i(TAG, "Permission " + moPowerManager.isIgnoringBatteryOptimizations(msPackageName));

        if (!moPowerManager.isIgnoringBatteryOptimizations(msPackageName)) {
            Intent loIntent = new Intent();
            loIntent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            loIntent.setData(Uri.parse("package:" + msPackageName));
            startActivity(loIntent);

        } 
    }

Please advice for this different behavior. and if there is a solution please let me know that. it's becoming frustrating.

RaRa
  • 2,024
  • 1
  • 18
  • 29
  • All manufacture are customization OS as per there need and UI,so battery performance will be vary to each device,it will work fine in following Device 1. All Nexus device 2. Google Pixel 3. All Motorola device All above uses pure Android but lets say Samsung, Sony Mi Asus all other manufacture override the existing feature of Android so it may possible due to this reason its not work well. – Premal Khetani Apr 10 '17 at 12:01
  • @iZattar can we check that the OS is pure android or its customized? by code. – RaRa Apr 10 '17 at 12:07
  • Sorry there is not such way to check weather to android OS is plain or customized programatically.but you can predict by certain feature like if its customize than call recording will give illegalArguments exception in default call recording work well so just like that you can predict by certain feature. – Premal Khetani Apr 10 '17 at 12:47
  • Hi @RaRa, Have you found any solution? I am facing the same issue with OnePlus7 and Realme5Pro devices(OS-10), After allowing on the popup the setting is not changed. – mdroid Jun 10 '20 at 17:56

0 Answers0