[代码] java代码
01
/**
02
* Indicates whether the specified action can be used as an intent. This
03
* method queries the package manager for installed packages that can
04
* respond to an intent with the specified action. If no suitable package is
05
* found, this method returns false.
06
*
07
* @param context The application's environment.
08
* @param action The Intent action to check for availability.
09
*
10
* @return True if an Intent with the specified action can be sent and
11
*responded to, false otherwise.
12
*/
13
public static boolean isIntentAvailable(Context context, String action) {
14
final PackageManager packageManager = context.getPackageManager();
15
final Intent intent = new Intent(action);
16
List<ResolveInfo> list =
17
packageManager.queryIntentActivities(intent,
18
PackageManager.MATCH_DEFAULT_ONLY);
19
return list.size() > 0;
20
}