确定Android中是否存在Intent Receiver

【确定Android中是否存在Intent Receiver】知识养成了思想,思想同时又在融化知识。这篇文章主要讲述确定Android中是否存在Intent Receiver相关的知识,希望能为你提供帮助。

  1. /**
  2.   * Indicates whether the specified action can be used as an intent. This
  3.   * method queries the package manager for installed packages that can
  4.   * respond to an intent with the specified action. If no suitable package is
  5.   * found, this method returns false.
  6.   *
  7.   * @param context The application's environment.
  8.   * @param action The Intent action to check for availability.
  9.   *
  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. }


    推荐阅读