Example usage for android.content Intent putExtra

List of usage examples for android.content Intent putExtra

Introduction

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

Prototype

@Deprecated
@UnsupportedAppUsage
public @NonNull Intent putExtra(String name, IBinder value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:Main.java

public static Intent actionGetCreateAccountIntent(final Context context, final String accountManagerType) {
    final Intent i = new Intent();
    i.setComponent(new ComponentName(context, "com.android.email.activity.setup.AccountSetupFinal"));
    i.putExtra(EXTRA_FLOW_MODE, FLOW_MODE_ACCOUNT_MANAGER);
    i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType);
    return i;/*from   w w w. ja  va  2 s .  c  o  m*/
}

From source file:Main.java

public static void applyPermission(Context context) {
    Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
    intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");
    intent.putExtra("packageName", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*  ww w. j  a  v a2  s.c om*/
}

From source file:Main.java

public static boolean sendMail(Context context, String destination, String subject, String body) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { destination };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    if (subject != null) {
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    }/*from  w  ww .  j  a  v  a 2s  . co m*/
    if (body != null) {
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    }
    emailIntent.setType("plain/text");

    boolean ret = true;
    try {
        context.startActivity(emailIntent);
    } catch (Exception e) {
        ret = false;
    }
    return ret;
}

From source file:Main.java

public static void shareViaSms(Context context, String subject, String text) {
    Intent intent = new Intent();
    intent.setType("text/plain");
    intent.setData(Uri.parse("sms:"));
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra("sms_body", text);
    context.startActivity(Intent.createChooser(intent, "Share via SMS"));
}

From source file:Main.java

public static void gotoActivity(Context ctx, Class<?> c, String[] name, String[] value) {
    // sendtoService(ctx, Constant.ACT_PLAY_SOUND, 0, String.valueOf(Constant.SOUND_FLINGED));
    Intent intent = new Intent(ctx, c);
    if (name != null)
        for (int i = 0; i < name.length; i++)
            intent.putExtra(name[i], value[i]);
    ctx.startActivity(intent);// w  ww  .j av  a 2  s . com
    ((Activity) ctx).finish();
}

From source file:Main.java

public static void callSysShare(Context context, String chooserTitle, String shareTitle, String shareText,
        String mime, Uri uri) {/*w  w w . j a  v  a  2 s  . c  o  m*/
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.putExtra(Intent.EXTRA_SUBJECT, shareTitle);
    intent.setType(mime);
    if (uri != null) {
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    }
    context.startActivity(Intent.createChooser(intent, chooserTitle));
}

From source file:Main.java

/**
 * Send an email via available mail activity
 * /* ww  w  .ja  v  a 2 s .  c  o  m*/
 * @param context       the app context
 * @param to            the email address send to
 * @param subject       the email subject
 * @param body          the email body
 * @param attachments   the uris for attachments
 */
public static void sendEmail(Context context, String to, String subject, String body, Uri... attachments) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);

    emailIntent.setType("plain/text");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, body);

    if (attachments != null && attachments.length != 0) {
        ArrayList<Uri> uris = new ArrayList<Uri>();

        for (int i = 0; i < attachments.length; i++)
            uris.add(attachments[i]);

        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }

    context.startActivity(Intent.createChooser(emailIntent, null));
}

From source file:Main.java

public static void jumpToActivityForResult(Context context, Class<? extends Activity> targetClass, int resultId,
        String... datas) {// w ww.  j  a  v a 2  s .com
    Intent datatIntent = new Intent(context, targetClass);
    if (datas != null) {
        for (int i = 0; i < datas.length; ++i) {
            datatIntent.putExtra("data" + i, datas[i]);
        }
    }

    ((Activity) context).startActivityForResult(datatIntent, resultId);
}

From source file:Main.java

/**
 * Builds an Intent to add a new event to the calendar.
 *
 * @param title The title of the event./*from w  w w .j a  va  2 s .  c o m*/
 * @param start The start date and time.
 * @param end   The end date and time.
 * @param where Where the event is held (e.g.: an address).
 */
public static Intent getAddEventIntent(final String title, final Date start, final Date end,
        final String where) {
    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setData(CalendarContract.Events.CONTENT_URI);
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.getTime());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTime());
    intent.putExtra(CalendarContract.Events.TITLE, title);

    if (where != null) {
        intent.putExtra(CalendarContract.Events.EVENT_LOCATION, where);
    }

    return intent;
}

From source file:Main.java

public static void putData(Context context, Class<?> activity, String key, String value) {
    Intent intent = new Intent();
    intent.setClass(context, activity);/* w  w  w  .  ja v a 2s . c o  m*/
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(key, value);
    context.startActivity(intent);
}