Example usage for android.content Intent hasCategory

List of usage examples for android.content Intent hasCategory

Introduction

In this page you can find the example usage for android.content Intent hasCategory.

Prototype

public boolean hasCategory(String category) 

Source Link

Document

Check if a category exists in the intent.

Usage

From source file:Main.java

public static boolean isSplashOpenedOverNavigationActivity(final Activity act, final Intent intent) {
    return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_MAIN)
            && !act.isTaskRoot() && intent.hasCategory(Intent.CATEGORY_LAUNCHER);
}

From source file:com.android.launcher3.InstallShortcutReceiver.java

/**
 * Returns true if the intent is a valid launch intent for a shortcut.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file./*from www .  ja va 2  s  .  co  m*/
 *
 * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be
 * duplicated or removed(unless the app is un-installed).
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
static boolean isValidShortcutLaunchIntent(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)
            && launchIntent.getExtras() == null && TextUtils.isEmpty(launchIntent.getDataString())) {
        return false;
    }
    return true;
}

From source file:com.dmcc.chatlibrary.ui.EaseBaseActivity.java

@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/
    //?launcher activity,?app???
    if (!isTaskRoot()) {
        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
            finish();//from   w w  w  .j  a va 2s.c  o  m
            return;
        }
    }
}

From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.EaseBaseActivity.java

@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();/*from ww  w  .j  ava2  s. c  o m*/
            return;
        }
    }
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:com.callba.phone.ui.ease.EaseBaseActivity.java

@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/
    //?launcher activity,?app???
    if (!isTaskRoot()) {
        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
            finish();//from ww w .j  a  va2 s. co  m
            return;
        }
    }

    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:cn.xcom.helper.chat.easeui.ui.EaseBaseActivity.java

@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();//from   w ww  .j  a  va  2 s .c o  m
            return;
        }
    }

    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:com.google.codelab.smartlock.MainActivity.java

/**
 * Set the appropriate fragment given the state of the Activity and the Intent used to start it.
 * If the intent is a launcher intent the Splash Fragment is shown otherwise the SignIn Fragment is shown.
 *
 * @param intent Intent used to determine which Fragment is used.
 *//* w  w w  .j av  a2  s .  c om*/
private void setFragment(Intent intent) {
    Fragment fragment;
    String tag;
    if (intent != null && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
        fragment = new SplashFragment();
        tag = SPLASH_TAG;
    } else {
        fragment = new SignInFragment();
        tag = SIGN_IN_TAG;
    }
    String currentTag = getCurrentFragmentTag();
    if (currentTag == null || !currentTag.equals(tag)) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, tag).commit();
    }
}

From source file:io.barracks.ota.client.helper.UpdateCheckHelper.java

/**
 * {@inheritDoc}//ww  w  . ja  va 2 s .c  o m
 */
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
    case UpdateCheckService.ACTION_CHECK:
        if (callback.hashCode() == intent.getIntExtra(UpdateCheckService.EXTRA_CALLBACK, 0)) {
            if (intent.hasCategory(UpdateCheckService.UPDATE_REQUEST_ERROR)) {
                callback.onUpdateRequestError(
                        (UpdateDetailsRequest) intent.getParcelableExtra(UpdateCheckService.EXTRA_REQUEST),
                        (Throwable) intent.getSerializableExtra(UpdateCheckService.EXTRA_EXCEPTION));
            } else if (intent.hasCategory(UpdateCheckService.UPDATE_AVAILABLE)) {
                callback.onUpdateAvailable(
                        (UpdateDetailsRequest) intent.getParcelableExtra(UpdateCheckService.EXTRA_REQUEST),
                        (UpdateDetails) intent.getParcelableExtra(UpdateCheckService.EXTRA_UPDATE_DETAILS));
            } else if (intent.hasCategory(UpdateCheckService.UPDATE_UNAVAILABLE)) {
                callback.onUpdateUnavailable(
                        (UpdateDetailsRequest) intent.getParcelableExtra(UpdateCheckService.EXTRA_REQUEST));
            }
        }
        break;
    }
}

From source file:io.barracks.ota.client.helper.PackageDownloadHelper.java

/**
 * {@inheritDoc}/*from w w  w  .j a v  a  2 s  . co m*/
 */
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
    case PackageDownloadService.ACTION_DOWNLOAD_PACKAGE:
        if (callback.hashCode() == intent.getIntExtra(UpdateCheckService.EXTRA_CALLBACK, 0)) {
            if (intent.hasCategory(PackageDownloadService.DOWNLOAD_PROGRESS)) {
                callback.onDownloadProgress(
                        intent.<UpdateDetails>getParcelableExtra(PackageDownloadService.EXTRA_UPDATE_DETAILS),
                        intent.getIntExtra(PackageDownloadService.EXTRA_PROGRESS, 0));
            } else if (intent.hasCategory(PackageDownloadService.DOWNLOAD_SUCCESS)) {
                callback.onDownloadSuccess(
                        intent.<UpdateDetails>getParcelableExtra(PackageDownloadService.EXTRA_UPDATE_DETAILS),
                        intent.getStringExtra(PackageDownloadService.EXTRA_FINAL_DEST));
            } else if (intent.hasCategory(PackageDownloadService.DOWNLOAD_ERROR)) {
                callback.onDownloadFailure(
                        intent.<UpdateDetails>getParcelableExtra(PackageDownloadService.EXTRA_UPDATE_DETAILS),
                        (Throwable) intent.getSerializableExtra(PackageDownloadService.EXTRA_EXCEPTION));
            }
        }
        break;
    }
}

From source file:com.purplefrog.glitchclocka.LearningReadout.java

/**
 * This intent can be activated two ways, by clicking on one of our AppWidgets, or is a callback from the OAuth mechanism.
 * This function returns true if we've been called from OAuth and need to harvest the auth data.
 * This function returns false if we've been activated by any other mechanism
 *//*from   w  ww .  j  a  v  a2s .c om*/
protected boolean checkStateMachine() {
    Intent intent = getIntent();

    if (intent.hasCategory(Intent.CATEGORY_BROWSABLE)) {
        final Uri uri = intent.getData();

        if (uri != null) {
            glitch.handleRedirect(uri, new MyGlitchSessionDelegate());
            return true;
        }
    }

    return false;
}