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

The following are Jave code examples for showing how to use hasCategory() 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: Hitalk   File: BaseActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    hideSoftKeyboard();
    mAppCtx = HiTalkApplication.mAppContext;

    sAliveActivities.add(this);
    checkAndInstallEatMark();

    params = removeParams(getIntent());
}
 
Example 2
Project: KTalk   File: EaseBaseActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example 3
Project: Tribe   File: EaseBaseActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

}
 
Example 4
Project: FanChat   File: EaseBaseActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example 5
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 6
Project: GCSApp   File: EaseBaseActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    ActivityManagerUtil.getInstance().pushOneActivity(this);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example 7
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 8
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 9
Project: Tribe   File: EaseBaseActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example 10
Project: Tribe   File: EaseBaseActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/
    // should be in launcher activity, but all app use this can avoid the problem
    if(!isTaskRoot()){
        Intent intent = getIntent();
        String action = intent.getAction();
        if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){
            finish();
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example 11
Project: buildAPKsSamples   File: Home.java   View Source Code Vote up 6 votes
/**
 * Refreshes the recently launched applications stacked over the favorites. The number
 * of recents depends on how many favorites are present.
 */
private void bindRecents() {
    final PackageManager manager = getPackageManager();
    final ActivityManager tasksManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    final List<ActivityManager.RecentTaskInfo> recentTasks = tasksManager.getRecentTasks(
            MAX_RECENT_TASKS, 0);

    final int count = recentTasks.size();
    final ArrayList<ApplicationInfo> recents = new ArrayList<ApplicationInfo>();

    for (int i = count - 1; i >= 0; i--) {
        final Intent intent = recentTasks.get(i).baseIntent;

        if (Intent.ACTION_MAIN.equals(intent.getAction()) &&
                !intent.hasCategory(Intent.CATEGORY_HOME)) {

            ApplicationInfo info = getApplicationInfo(manager, intent);
            if (info != null) {
                info.intent = intent;
                if (!mFavorites.contains(info)) {
                    recents.add(info);
                }
            }
        }
    }

    mApplicationsStack.setRecents(recents);
}
 
Example 12
Project: prevent   File: PreventRunningUtils.java   View Source Code Vote up 6 votes
public static int onStartActivity(int res, IApplicationThread caller, String callingPackage, Intent intent) {
    if (res >= 0 && intent != null && (intent.hasCategory(Intent.CATEGORY_HOME) || intent.hasCategory(Intent.CATEGORY_LAUNCHER))) {
        ProcessRecord callerApp = getAms().getRecordForAppLocked(caller);
        if (callerApp != null) {
            mPreventRunning.onStartHomeActivity(callerApp.info.packageName);
        }
    }
    return res;
}
 
Example 13
Project: Mobike   File: BaseActivity.java   View Source Code Vote up 6 votes
protected void onCreate(@Nullable Bundle paramBundle) {
    super.onCreate(paramBundle);
    if (!isTaskRoot()) {
        Intent localIntent = getIntent();
        String str = localIntent.getAction();
        if ((localIntent.hasCategory("android.intent.category.LAUNCHER")) && (str.equals("android.intent.action.MAIN")))
            finish();
    }
}
 
Example 14
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 15
Project: Trivia-Knowledge   File: SplashScreen.java   View Source Code Vote up 5 votes
@Override
public void initSplash(ConfigSplash configSplash) {
    if (!isTaskRoot()) {
        final Intent intent = getIntent();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
            Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
            finish();
            return;
        }
    }
        /* you don't have to override every property */

    //Customize Circular Reveal
    configSplash.setBackgroundColor(R.color.lightbluesplash); //any color you want form colors.xml
    configSplash.setAnimCircularRevealDuration(1000); //int ms
    configSplash.setRevealFlagX(Flags.REVEAL_RIGHT);  //or Flags.REVEAL_LEFT
    configSplash.setRevealFlagY(Flags.REVEAL_BOTTOM); //or Flags.REVEAL_TOP

    //Choose LOGO OR PATH; if you don't provide String value for path it's logo by default

    //Customize Logo
    configSplash.setLogoSplash(R.drawable.cglogo); //or any other drawable
    configSplash.setAnimLogoSplashDuration(1000); //int ms
    configSplash.setAnimLogoSplashTechnique(Techniques.FadeIn); //choose one form Techniques (ref: https://github.com/daimajia/AndroidViewAnimations)


    //Customize Path
    // configSplash.setPathSplash(Constants.DROID_LOGO); //set path String
    configSplash.setOriginalHeight(400); //in relation to your svg (path) resource
    configSplash.setOriginalWidth(400); //in relation to your svg (path) resource
    configSplash.setAnimPathStrokeDrawingDuration(1000);
    configSplash.setPathSplashStrokeSize(3); //I advise value be <5
    configSplash.setPathSplashStrokeColor(R.color.lightbluesplash); //any color you want form colors.xml
    configSplash.setAnimPathFillingDuration(1000);
    configSplash.setPathSplashFillColor(R.color.white); //path object filling color


    //Customize Title
    configSplash.setTitleSplash(getResources().getString(R.string.charetakergames));
    configSplash.setTitleTextColor(R.color.white);
    configSplash.setTitleTextSize(20f); //float value
    configSplash.setAnimTitleDuration(0);
    configSplash.setAnimTitleTechnique(Techniques.FadeIn);
    configSplash.setTitleFont("fonts/grobold.ttf"); //provide string to your font located in assets/fonts/

}