意图对话框 Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

Dialog for intent Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

我正在使用 Android 6 和 Cyanogenmod,当我开始执行以下意图时,没有任何反应!

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);
    ...

是否应该出现电池优化对话框?如果是这样,我做错了什么?

您的清单中需要包含这一行:

    <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>