Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:me.tassoevan.cordova.GoHomePlugin.java

private boolean doGoHomeAction(JSONArray args, CallbackContext callbackContext) {
    try {/*www  .  ja v  a  2 s  . c om*/
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        this.cordova.getActivity().startActivity(i);
        callbackContext.success();
        return true;
    } catch (Exception e) {
        this.logError("Exception occurred: ".concat(e.getMessage()));
        callbackContext.error("Exception occurred: ".concat(e.getMessage()));
        return false;
    }
}

From source file:com.phonegap.plugins.startapp.StartApp.java

/**
 * Starts an activity.//from  w  w  w .ja va 2 s .  c o m
 *
 * @param component
 *            Activity ComponentName.
 *            E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity
 */
void startActivity(String component) {
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setComponent(ComponentName.unflattenFromString(component));
    this.ctx.startActivity(intent);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToWebSessionObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra("android.intent.extra.APPLICATION_ARGUMENT", arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String webUrl = obj.optString(WEB_URL);
    launch.setData(Uri.parse(webUrl));//w w  w  . j a  v  a 2 s  . c  om
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received",
            "Click to launch application.", contentIntent);
}

From source file:love.juhe.androidmonkey.MonkeyActivityEvent.java

/**
 * @return Intent for the new activity/*  w w  w . j  a  va  2 s.c  o m*/
 */
private Intent getEvent() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(mApp);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:com.android.deskclock.alarms.AlarmStateManager.java

/**
 * Utility method to create a proper change state intent.
 *
 * @param context application context//w w  w.  j av  a 2 s. c  om
 * @param tag used to make intent differ from other state change intents.
 * @param instance to change state to
 * @param state to change to.
 * @return intent that can be used to change an alarm instance state
 */
public static Intent createStateChangeIntent(Context context, String tag, AlarmInstance instance,
        Integer state) {
    // This intent is directed to AlarmService, though the actual handling of it occurs here
    // in AlarmStateManager. The reason is that evidence exists showing the jump between the
    // broadcast receiver (AlarmStateManager) and service (AlarmService) can be thwarted by the
    // Out Of Memory killer. If clock is killed during that jump, firing an alarm can fail to
    // occur. To be safer, the call begins in AlarmService, which has the power to display the
    // firing alarm if needed, so no jump is needed.
    Intent intent = AlarmInstance.createIntent(context, AlarmService.class, instance.mId);
    intent.setAction(CHANGE_STATE_ACTION);
    intent.addCategory(tag);
    intent.putExtra(ALARM_GLOBAL_ID_EXTRA, getGlobalIntentId(context));
    if (state != null) {
        intent.putExtra(ALARM_STATE_EXTRA, state.intValue());
    }
    return intent;
}

From source file:com.google.zxing.BarcodeScanner.java

/**
* Starts an intent to scan and decode a barcode.
*///from  w w  w.  j a v a 2  s. co m
public void scan() {
    Intent intentScan = new Intent(SCAN_INTENT);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    this.cordova.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE);
}

From source file:com.cordova.plugins.startapp.StartApp.java

/**
 * Starts an activity.//from w w  w .ja va2s.com
 *
 * @param component
 *            Activity ComponentName.
 *            E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity
 */
void startActivity(String component) {
    try {
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        intent.setComponent(ComponentName.unflattenFromString(component));
        ((DroidGap) this.cordova.getActivity()).startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        /**
         * If not installed, open market
         */
        String[] packageNameSplt = component.split("/");
        String packageName = packageNameSplt[0];

        Intent marketIntent = new Intent(Intent.ACTION_VIEW);
        marketIntent.setData(Uri.parse("market://details?id=" + packageName));
        ((DroidGap) this.cordova.getActivity()).startActivity(marketIntent);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.setComponent(new ComponentName(context.getPackageName(), HomeActivity.class.getName()));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    String msg = obj.optString(TEXT);
    (new PresenceAwareNotify(context)).notify("IM from " + from.name, "IM from " + from.name, "\"" + msg + "\"",
            contentIntent);/* www. java  2 s  .co m*/
}

From source file:cn.newgxu.android.notty.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.dark_theme:
        ThemeUtils.apply(this, ThemeUtils.DARK_THEME);
        break;/*from   www. ja va 2  s  . c o m*/
    case R.id.light_theme:
        ThemeUtils.apply(this, ThemeUtils.LIGHT_THEME);
        break;
    case R.id.refresh:
        Intent intent = new Intent(this, FetchService.class);
        String[] uris = { C.BASE_URI + C.NOTICES, C.BASE_URI + C.USERS };
        intent.putExtra("uris", uris);
        //         TODO: ???
        intent.putExtra(C.URI, C.DOMAIN + "/info/notices?type=4&count=50");
        startService(intent);
        break;
    case R.id.logout:
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
        break;
    case R.id.about:
        AboutBoxDialogFragment about = new AboutBoxDialogFragment();
        about.show(fm, "about");
        break;
    default:
        break;
    }
    return true;
}

From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java

/**
 * Utility method to create a proper change state intent.
 *
 * @param context  application context/*from   w w  w  .ja v a  2 s.  c  o m*/
 * @param tag      used to make intent differ from other state change intents.
 * @param instance to change state to
 * @param state    to change to.
 * @return intent that can be used to change an alarm instance state
 */
public static Intent createStateChangeIntent(Context context, String tag, AlarmInstance instance,
        Integer state) {
    // This intent is directed to AlarmService, though the actual handling of it occurs here
    // in AlarmStateManager. The reason is that evidence exists showing the jump between the
    // broadcast receiver (AlarmStateManager) and service (AlarmService) can be thwarted by the
    // Out Of Memory killer. If clock is killed during that jump, firing an alarm can fail to
    // occur. To be safer, the call begins in AlarmService, which has the power to display the
    // firing alarm if needed, so no jump is needed.
    Intent intent = AlarmInstance.createIntent(context, AlarmService.class, instance.mId);
    intent.setAction(CHANGE_STATE_ACTION);
    intent.addCategory(tag);
    intent.putExtra(ALARM_GLOBAL_ID_EXTRA, DataModel.getDataModel().getGlobalIntentId());
    if (state != null) {
        intent.putExtra(ALARM_STATE_EXTRA, state.intValue());
    }
    return intent;
}