Java Code Examples for android.content.Intent.getCategories()

The following are Jave code examples for showing how to use getCategories() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VirtualHook   File: ResolverActivity.java   View Source Code Vote up 7 votes
@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
    final int titleResource;
    final Intent intent = makeMyIntent();
    final Set<String> categories = intent.getCategories();
    if (Intent.ACTION_MAIN.equals(intent.getAction())
            && categories != null
            && categories.size() == 1
            && categories.contains(Intent.CATEGORY_HOME)) {
        titleResource = R.string.choose;
    } else {
        titleResource = R.string.choose;
    }

    onCreate(savedInstanceState, intent, getResources().getText(titleResource),
            null, null, true, VUserHandle.getCallingUserId());
}
 
Example 2
Project: TPlayer   File: ResolverActivity.java   View Source Code Vote up 7 votes
@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
    final int titleResource;
    final Intent intent = makeMyIntent();
    final Set<String> categories = intent.getCategories();
    if (Intent.ACTION_MAIN.equals(intent.getAction())
            && categories != null
            && categories.size() == 1
            && categories.contains(Intent.CATEGORY_HOME)) {
        titleResource = R.string.choose;
    } else {
        titleResource = R.string.choose;
    }

    onCreate(savedInstanceState, intent, getResources().getText(titleResource),
            null, null, true, VUserHandle.getCallingUserId());
}
 
Example 3
Project: FlickLauncher   File: Utilities.java   View Source Code Vote up 7 votes
/**
 * Returns true if the intent is a valid launch intent for a launcher activity of an app.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file.
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
public static boolean isLauncherAppTarget(Intent launchIntent) {
    if (launchIntent != null
            && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null
            && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1
            && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && TextUtils.isEmpty(launchIntent.getDataString())) {
        // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
        Bundle extras = launchIntent.getExtras();
        if (extras == null) {
            return true;
        } else {
            Set<String> keys = extras.keySet();
            return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE);
        }
    };
    return false;
}
 
Example 4
Project: container   File: ResolverActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    final int titleResource;
    final Intent intent = makeMyIntent();
    final Set<String> categories = intent.getCategories();
    if (Intent.ACTION_MAIN.equals(intent.getAction())
            && categories != null
            && categories.size() == 1
            && categories.contains(Intent.CATEGORY_HOME)) {
        titleResource = R.string.choose;
    } else {
        titleResource = R.string.choose;
    }

    onCreate(savedInstanceState, intent, getResources().getText(titleResource),
            null, null, true, VUserHandle.getCallingUserId());
}
 
Example 5
Project: SimpleUILauncher   File: Utilities.java   View Source Code Vote up 7 votes
/**
 * Returns true if the intent is a valid launch intent for a launcher activity of an app.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file.
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
public static boolean isLauncherAppTarget(Intent launchIntent) {
    if (launchIntent != null
            && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null
            && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1
            && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && TextUtils.isEmpty(launchIntent.getDataString())) {
        // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
        Bundle extras = launchIntent.getExtras();
        if (extras == null) {
            return true;
        } else {
            Set<String> keys = extras.keySet();
            return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE);
        }
    };
    return false;
}
 
Example 6
Project: CleanArchitechture   File: Logger.java   View Source Code Vote up 6 votes
public static void dump(Intent intent) {
    if (intent == null) {
        e("Intent is null");
        return;
    }

    e("Intent: action: %s", intent.getAction());

    if (intent.getPackage() != null) {
        e("  pkg: %s", intent.getPackage());
    }

    if (intent.getType() != null) {
        e("  type: %s", intent.getType());
    }

    if (intent.getComponent() != null) {
        e("  comp: %s", intent.getComponent().flattenToString());
    }

    if (intent.getDataString() != null) {
        e("  data: %s", intent.getDataString());
    }

    if (intent.getCategories() != null) {
        for (String cat : intent.getCategories()) {
            e("  cat: %s", cat);
        }
    }

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        for (String key : bundle.keySet()) {
            Object value = bundle.get(key);
            e("  extra: %s->%s", key, value);
        }
    }

}
 
Example 7
Project: kognitivo   File: MessengerUtils.java   View Source Code Vote up 6 votes
/**
 * When handling an {@code Intent} from Messenger, call this to parse the parameters of the
 * intent.
 *
 * @param intent the intent of the activity
 * @return a {@link MessengerThreadParams} or null if this intent wasn't recognized as a request
 *     from Messenger to share.
 */
public static MessengerThreadParams getMessengerThreadParamsForIntent(Intent intent) {
  Set<String> categories = intent.getCategories();
  if (categories == null) {
    return null;
  }
  if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
    Bundle appLinkExtras = AppLinks.getAppLinkExtras(intent);
    String threadToken = appLinkExtras.getString(EXTRA_THREAD_TOKEN_KEY);
    String metadata = appLinkExtras.getString(EXTRA_METADATA);
    String participants = appLinkExtras.getString(EXTRA_PARTICIPANTS);
    boolean isReply = appLinkExtras.getBoolean(EXTRA_IS_REPLY);
    boolean isCompose = appLinkExtras.getBoolean(EXTRA_IS_COMPOSE);
    MessengerThreadParams.Origin origin = MessengerThreadParams.Origin.UNKNOWN;
    if (isReply) {
      origin = MessengerThreadParams.Origin.REPLY_FLOW;
    } else if (isCompose) {
      origin = MessengerThreadParams.Origin.COMPOSE_FLOW;
    }

    return new MessengerThreadParams(
        origin,
        threadToken,
        metadata,
        parseParticipants(participants));
  } else {
    return null;
  }
}
 
Example 8
Project: kognitivo   File: MessengerUtils.java   View Source Code Vote up 6 votes
/**
 * Finishes the activity and returns the media item the user picked to Messenger.
 *
 * @param activity the activity that received the original intent from Messenger
 * @param shareToMessengerParams parameters for what to share
 */
public static void finishShareToMessenger(
    Activity activity,
    ShareToMessengerParams shareToMessengerParams) {
  Intent originalIntent = activity.getIntent();
  Set<String> categories = originalIntent.getCategories();
  if (categories == null) {
    // This shouldn't happen.
    activity.setResult(Activity.RESULT_CANCELED, null);
    activity.finish();
    return;
  }

  if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
    Bundle appLinkExtras = AppLinks.getAppLinkExtras(originalIntent);

    Intent resultIntent = new Intent();
    if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
      resultIntent.putExtra(EXTRA_PROTOCOL_VERSION, MessengerUtils.PROTOCOL_VERSION_20150314);
      String threadToken = appLinkExtras.getString(MessengerUtils.EXTRA_THREAD_TOKEN_KEY);
      resultIntent.putExtra(EXTRA_THREAD_TOKEN_KEY, threadToken);
    } else {
      throw new RuntimeException(); // Can't happen.
    }
    resultIntent.setDataAndType(shareToMessengerParams.uri, shareToMessengerParams.mimeType);
    resultIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    resultIntent.putExtra(EXTRA_APP_ID, FacebookSdk.getApplicationId());
    resultIntent.putExtra(EXTRA_METADATA, shareToMessengerParams.metaData);
    resultIntent.putExtra(EXTRA_EXTERNAL_URI, shareToMessengerParams.externalUri);
    activity.setResult(Activity.RESULT_OK, resultIntent);
    activity.finish();
  } else {
    // This shouldn't happen.
    activity.setResult(Activity.RESULT_CANCELED, null);
    activity.finish();
  }
}
 
Example 9
Project: LaunchEnr   File: Utilities.java   View Source Code Vote up 6 votes
/**
 * Returns true if the intent is a valid launch intent for a launcher activity of an app.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file.
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
public static boolean isLauncherAppTarget(Intent launchIntent) {
    if (launchIntent != null
            && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null
            && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1
            && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && TextUtils.isEmpty(launchIntent.getDataString())) {
        // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
        Bundle extras = launchIntent.getExtras();
        return extras == null || extras.keySet().isEmpty();
    }
    return false;
}
 
Example 10
Project: atlas   File: IntentResolver.java   View Source Code Vote up 6 votes
private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) {
    final Set<String> categories = intent.getCategories();
    if (categories == null) {
        return null;
    }
    return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()]));
}
 
Example 11
Project: chromium-for-android-56-debug-video   File: VrShellDelegate.java   View Source Code Vote up 6 votes
/**
 * Whether or not the intent is a Daydream VR Intent.
 */
public boolean isVrIntent(Intent intent) {
    if (intent == null) return false;
    if (intent.getBooleanExtra(DAYDREAM_VR_EXTRA, false)) return true;
    if (intent.getCategories() != null) {
        if (intent.getCategories().contains(DAYDREAM_CATEGORY)) return true;
        if (intent.getCategories().contains(CARDBOARD_CATEGORY)) return true;
    }
    return false;
}
 
Example 12
Project: VirtualHook   File: IntentResolver.java   View Source Code Vote up 6 votes
private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) {
	final Set<String> categories = intent.getCategories();
	if (categories == null) {
		return null;
	}
	return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()]));
}
 
Example 13
Project: OpenYOLO-Android   File: QueryUtilTest.java   View Source Code Vote up 6 votes
@Test
public void testCreateEmptyQueryIntent_ValidData() throws Exception {
    String mockCategory = "MockCategory";
    Intent result = QueryUtil.createEmptyQueryIntent(mockCategory);
    Set<String> categories = result.getCategories();
    assertEquals(1, categories.size());
    assertTrue(categories.contains(QueryUtil.BBQ_CATEGORY));
    result.getAction().equals(mockCategory);
}
 
Example 14
Project: TPlayer   File: IntentResolver.java   View Source Code Vote up 6 votes
private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) {
	final Set<String> categories = intent.getCategories();
	if (categories == null) {
		return null;
	}
	return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()]));
}
 
Example 15
Project: IFWManager   File: IntentResolver.java   View Source Code Vote up 6 votes
private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) {
    final Set<String> categories = intent.getCategories();
    if (categories == null) {
        return null;
    }
    return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()]));
}
 
Example 16
Project: IFWManager   File: CategoryFilter.java   View Source Code Vote up 6 votes
@Override
public boolean matches(IntentFirewall ifw, ComponentName resolvedComponent, Intent intent,
                       int callerUid, int callerPid, String resolvedType, int receivingUid) {
    Set<String> categories = intent.getCategories();
    if (categories == null) {
        return false;
    }
    return categories.contains(mCategoryName);
}
 
Example 17
Project: container   File: IntentResolver.java   View Source Code Vote up 6 votes
private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) {
	final Set<String> categories = intent.getCategories();
	if (categories == null) {
		return null;
	}
	return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()]));
}
 
Example 18
Project: chromium-for-android-56-debug-video   File: IntentHandler.java   View Source Code Vote up 5 votes
/**
 * Returns true if the app should ignore a given intent.
 *
 * @param context Android Context.
 * @param intent Intent to check.
 * @return true if the intent should be ignored.
 */
public boolean shouldIgnoreIntent(Context context, Intent intent) {
    // Although not documented to, many/most methods that retrieve values from an Intent may
    // throw. Because we can't control what packages might send to us, we should catch any
    // Throwable and then fail closed (safe). This is ugly, but resolves top crashers in the
    // wild.
    try {
        // Ignore all invalid URLs, regardless of what the intent was.
        if (!intentHasValidUrl(intent)) {
            return true;
        }

        // Determine if this intent came from a trustworthy source (either Chrome or Google
        // first party applications).
        boolean isInternal = isIntentChromeOrFirstParty(intent, context);

        // "Open new incognito tab" is currently limited to Chrome or first parties.
        if (!isInternal
                && IntentUtils.safeGetBooleanExtra(
                        intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
                && (getPendingIncognitoUrl() == null
                        || !getPendingIncognitoUrl().equals(intent.getDataString()))) {
            return true;
        }

        // Now if we have an empty URL and the intent was ACTION_MAIN,
        // we are pretty sure it is the launcher calling us to show up.
        // We can safely ignore the screen state.
        String url = getUrlFromIntent(intent);
        if (url == null && Intent.ACTION_MAIN.equals(intent.getAction())) {
            return false;
        }

        // Ignore all intents that specify a Chrome internal scheme if they did not come from
        // a trustworthy source.
        String scheme = getSanitizedUrlScheme(url);
        if (!isInternal && scheme != null
                && (intent.hasCategory(Intent.CATEGORY_BROWSABLE)
                           || intent.hasCategory(Intent.CATEGORY_DEFAULT)
                           || intent.getCategories() == null)) {
            String lowerCaseScheme = scheme.toLowerCase(Locale.US);
            if ("chrome".equals(lowerCaseScheme) || "chrome-native".equals(lowerCaseScheme)
                    || "about".equals(lowerCaseScheme)) {
                // Allow certain "safe" internal URLs to be launched by external
                // applications.
                String lowerCaseUrl = url.toLowerCase(Locale.US);
                if ("about:blank".equals(lowerCaseUrl)
                        || "about://blank".equals(lowerCaseUrl)) {
                    return false;
                }

                Log.w(TAG, "Ignoring internal Chrome URL from untrustworthy source.");
                return true;
            }
        }

        // We must check for screen state at this point.
        // These might be slow.
        boolean internalOrVisible = isInternal || isIntentUserVisible(context);
        return !internalOrVisible;
    } catch (Throwable t) {
        return true;
    }
}
 
Example 19
Project: springreplugin   File: IntentMatcherHelper.java   View Source Code Vote up 5 votes
/**
 * 根据 Intent 匹配组件
 *
 * @param context    Context
 * @param intent     调用方传来的 Intent
 * @param filtersMap 插件中声明的所有组件和 IntentFilter
 * @return ComponentInfo
 */
public static String doMatchIntent(Context context, Intent intent, Map<String, List<IntentFilter>> filtersMap) {
    if (filtersMap == null) {
        return null;
    }

    final String action = intent.getAction();
    final String type = intent.resolveTypeIfNeeded(context.getContentResolver());
    final Uri data = intent.getData();
    final String scheme = intent.getScheme();
    final Set<String> categories = intent.getCategories();

    for (Map.Entry<String, List<IntentFilter>> entry : filtersMap.entrySet()) {
        String pluginName = entry.getKey();
        List<IntentFilter> filters = entry.getValue();
        if (filters == null) {
            continue;
        }

        for (IntentFilter filter : filters) {
            int match = filter.match(action, type, scheme, data, categories, "ComponentList");
            if (match >= 0) {
                if (LOG) {
                    LogDebug.d(TAG, "IntentFilter 匹配成功: " + entry.getKey());
                }
                return pluginName;
            } else {
                if (LOG) {
                    String reason;
                    switch (match) {
                        case IntentFilter.NO_MATCH_ACTION:
                            reason = "action";
                            break;
                        case IntentFilter.NO_MATCH_CATEGORY:
                            reason = "category";
                            break;
                        case IntentFilter.NO_MATCH_DATA:
                            reason = "data";
                            break;
                        case IntentFilter.NO_MATCH_TYPE:
                            reason = "type";
                            break;
                        default:
                            reason = "unknown reason";
                            break;
                    }
                    LogDebug.d(TAG, "  Filter did not match: " + reason);
                }
            }
        }
    }
    return "";
}