[英]How solve a Fatal Exception in android.content.ActivityNotFoundException Error
I'm trying to guide my users to the battery optimizations activity and it seems to be working for most except for some Samsung phones with Android 6 where I get 我正在尝试引导用户进行电池优化活动,该功能似乎对大多数用户都有效,除了一些装有Android 6的三星手机
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS }
This error Showed in OPPO F3 Mobiles, This is what I am using to launch it 此错误在OPPO F3手机中显示,这是我用来启动它的原因
Intent intent = new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
startActivity(intent);
Any idea what I should be launching on those phones? 知道我应该在这些手机上启动什么吗?
Thanks. 谢谢。
On some devices this activity may not exist, because of custom firmware. 在某些设备上,由于自定义固件,此活动可能不存在。
You can check your intent by using this method: 您可以使用以下方法检查您的意图:
private static boolean isIntentAvailable(@NonNull Context context, @NonNull Intent intent) {
return context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
And when you do startActivity do this: 当您执行startActivity时,请执行以下操作:
Intent intent = new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
if (isIntentAvailable(this, intent)) {
startActivity(intent);
} else {
// Do something else
}
Or catch your exception. 还是抓住你的例外。 Or find these custom activities on problem devices and call them.
或者在有问题的设备上找到这些自定义活动,然后调用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.