How can I keep app running through Ultra Battery Saver mode / Adb shell uninstall Ultra Battery Saver ? (No root)

667 Views Asked by At

I am trying to disable the option to start ultra battery saver mode on Miui 11 without root acces. Is it possible to do this? I have tried to uninstall com.miui.securitycenter which helps up untill the first restart. Then it enters a bootloop and the phone needs to be wiped.

Alternatively, It would be helpful if I could make an app run permanently, even in Ultra Battery Saver Mode.

1

There are 1 best solutions below

0
Amirbidar On

Without rooting the device , this is not possible, but you can ask user to ignore battery saver mode for you by leading user to setting like this:

PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (pm != null && !pm.isIgnoringBatteryOptimizations(getPackageName())) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + getPackageName()));
            startActivity(intent);
        }
    }
}

also keep that in mind that if you use this code , you will have some hard time publishing your app in Google Play Store.