android.content.ActivityNotFoundException“android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS”

问题描述 投票:4回答:1

我正在尝试引导我的用户进行电池优化活动,它似乎适用于大多数除了一些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);

知道我应该在那些手机上推出什么?

谢谢。

android android-6.0-marshmallow
1个回答
-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);
            }
        }
© www.soinside.com 2019 - 2024. All rights reserved.