Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialog for intent Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

I am using Android 6 with Cyanogenmod and when I am starting the following intent, then nothing happens!

if(Build.VERSION.SDK_INT >= Constants.IGNORE_BATTERY_OPTIMIZATIONS_MIN_BUILD) {
                    String packageName = getPackageName();
                    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                    if (!pm.isIgnoringBatteryOptimizations(packageName)) {
                        Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).setData(Uri.parse("package:" + packageName));
                        try {
                            startActivity(intent);
    ...

Should the dialog for the Battery optimisation come up? If so, what am I doing wrong?

like image 974
egmontr Avatar asked Mar 11 '23 15:03

egmontr


1 Answers

You need to have this line in your manifest:

    <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
like image 99
Janne Oksanen Avatar answered Apr 27 '23 10:04

Janne Oksanen