ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS has no effect on some Android 10 devices

Viewed 110

I'm trying to tell the device that my app should not be interrupted following Google's recommandations.

This works on many device but has no effect on some others. Every manufacturer seems to be able to do whatever he wants.

For example, the HONOR 20 Lite (Android 10) has an option that is not affected by the standard system dialog to add the app to the exemption list.

I'm wondering what I can do about this. I think that it would be a poor user experience to have the user to figure it out by himself.

1 Answers

I hope this method code is help full for you

public float getBatteryLevel(){
        Intent betteryInent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        int level = betteryInent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
        int scale = betteryInent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
        if (level == -1 ||scale == -1 ){
            return  50.0f;
        }
        return ((float)level / (float) scale * 100.0f);
    }
Related