简体   繁体   English

如何解决android.content.ActivityNotFoundException错误中的致命异常

[英]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.

相关问题 致命异常:android.content.ActivityNotFoundException:未找到处理 Intent 的活动 - Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent android.content.ActivityNotFoundException出错 - Error android.content.ActivityNotFoundException android.content.ActivityNotFoundException: - android.content.ActivityNotFoundException: android.content.activitynotfoundexception - android.content.activitynotfoundexception android.content.ActivityNotFoundException很多 - android.content.ActivityNotFoundException a lot StartActivity上的Android.Content.ActivityNotFoundException - Android.Content.ActivityNotFoundException at StartActivity Android错误:“ android.content.ActivityNotFoundException:未找到用于处理Intent的活动” - Android error : “android.content.ActivityNotFoundException: No Activity found to handle Intent” android.content.ActivityNotFoundException:未找到处理意图错误的活动 - android.content.ActivityNotFoundException: No Activity found to handle Intent error 错误 android.content.ActivityNotFoundException:仅在极少数设备中 - Error android.content.ActivityNotFoundException: only in very few devices 我该如何修复'android.content.ActivityNotFoundException'? - How can I fix 'android.content.ActivityNotFoundException'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM