android.content.ActivityNotFoundException" android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"

时间:2017-03-20 16:37:04

标签: android android-6.0-marshmallow

我试图引导我的用户进行电池优化活动,除了一些Android手机的三星手机外,它似乎最适用:

Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS }

这是我用它来启动它:

Intent intent = new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
startActivity(intent);

知道我应该在这些手机上发布什么内容吗?

感谢。

1 个答案:

答案 0 :(得分:-2)

使用以下代码检查您的应用是否已被忽略以进行电池优化,如果是,则显示弹出窗口以启用相同功能。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            if (!pm.isIgnoringBatteryOptimizations(getPackageName())) {

                Intent batterySaverIntent=new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:"+getPackageName()));
                startActivity(batterySaverIntent);
            }
        }