我正在一个需要通过 DOZE 的 Android 6 中测试一个应用程序,因为我想请求用户接受电池优化的问题。
与项目 AntiDoze 一样,但是当我在虚拟设备中运行时,我没有任何问题,但是当我传递给三星时,我得到:
FATAL EXCEPTION: main
Process: com.commonsware.android.antidoze, PID: 21135
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.commonsware.android.antidoze/com.commonsware.android.antidoze.EventDemoActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS dat=package:com.commonsware.android.antidoze }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
知道如何解决这个问题吗?
链接中重要的代码是:
if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP_MR1) {
String pkg=getPackageName();
PowerManager pm=getSystemService(PowerManager.class);
if (!pm.isIgnoringBatteryOptimizations(pkg)) {
Intent i=
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:"+pkg));
startActivity(i);
}
}
在清单中我有
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />