判断是否有响应Intent的app


/**
	 * 获取能启动intent的app信息
	 * 
	 * @param context
	 * @param intent
	 * @return
	 */
	public static List<ResolveInfo> getAppsForIntent(Context context,
			Intent intent) {
		PackageManager packageManager = context.getPackageManager();
		// 属性
		List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(
				intent, PackageManager.MATCH_DEFAULT_ONLY);

		for (ResolveInfo info : resolveInfo) {
			LogUtil.d("resolve info:" + info.activityInfo.packageName);
		}

		return resolveInfo;
	}

	/**
	 * 是否有启动intent的app
	 * 
	 * @param context
	 * @param intent
	 * @return
	 */
	public static boolean hasAppsStartIntent(Context context, Intent intent) {
		List<ResolveInfo> appInfos = getAppsForIntent(context, intent);
		return appInfos != null && appInfos.size() > 0;
	}





需要权限。


你可能感兴趣的:(android,intent)