特此抗议全是vip文章
判断安卓应用Intent或Action在系统中是否能被启动
/**
* @param context The application's environment.
* @param intent The Intent to check for availability.
* @return True if an Intent with the specified action can be sent and
* responded to, false otherwise.
*/
public static boolean isIntentAvailable(Context context, Intent intent) {
if((null == context) || (null == intent))
return false;
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(null == list)
return false;
return list.size() > 0;
}
还可以将参数intent替换为action,在函数内new一个Intent再进行判断。
本文介绍了一个用于检测Android应用中的Intent或Action是否能在系统中被成功启动的方法。通过提供的静态函数isIntentAvailable,开发者可以轻松地验证指定Intent的有效性。

372

被折叠的 条评论
为什么被折叠?



