コード例 #1
1
  /**
   * 获取目标类型,activity or service or broadcast
   *
   * @param intent
   * @return
   */
  public static int getTargetType(Intent intent) {

    Iterator<PluginDescriptor> itr = getPlugins().iterator();

    while (itr.hasNext()) {
      PluginDescriptor plugin = itr.next();
      // 如果是通过组件进行匹配的
      if (intent.getComponent() != null) {
        if (plugin.containsName(intent.getComponent().getClassName())) {
          return plugin.getType(intent.getComponent().getClassName());
        }
      } else {
        String clazzName = findClassNameByIntent(intent, plugin.getActivitys());

        if (clazzName == null) {
          clazzName = findClassNameByIntent(intent, plugin.getServices());
        }

        if (clazzName == null) {
          clazzName = findClassNameByIntent(intent, plugin.getReceivers());
        }

        if (clazzName != null) {
          return plugin.getType(clazzName);
        }
      }
    }
    return PluginDescriptor.UNKOWN;
  }
コード例 #2
1
  /**
   * //If getComponent returns an explicit class, that is returned without any further
   * consideration. //If getAction is non-NULL, the activity must handle this action. //If
   * resolveType returns non-NULL, the activity must handle this type. //If addCategory has added
   * any categories, the activity must handle ALL of the categories specified. //If getPackage is
   * non-NULL, only activity components in that application package will be considered.
   *
   * @param intent
   * @return
   */
  public static String matchPlugin(Intent intent) {

    Iterator<PluginDescriptor> itr = getPlugins().iterator();

    while (itr.hasNext()) {
      PluginDescriptor plugin = itr.next();
      // 如果是通过组件进行匹配的
      if (intent.getComponent() != null) {
        if (plugin.containsName(intent.getComponent().getClassName())) {
          return intent.getComponent().getClassName();
        }
      } else {
        // 如果是通过IntentFilter进行匹配的
        String clazzName = findClassNameByIntent(intent, plugin.getActivitys());

        if (clazzName == null) {
          clazzName = findClassNameByIntent(intent, plugin.getServices());
        }

        if (clazzName == null) {
          clazzName = findClassNameByIntent(intent, plugin.getReceivers());
        }

        if (clazzName != null) {
          return clazzName;
        }
      }
    }
    return null;
  }