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 getSmsIntent(String number, String body) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("smsto:" + number));
    intent.putExtra("sms_body", body);
    return intent;
}

From source file:Main.java

public static void callGoogleTranslateApps(Context context, String word, String toLang) {
    try {//from   www .  ja  v a 2s  .c o m
        Intent i = new Intent();

        i.setAction(Intent.ACTION_VIEW);

        i.putExtra("key_text_input", word);
        i.putExtra("key_text_output", "");
        i.putExtra("key_language_from", "en");
        i.putExtra("key_language_to", "vi");
        i.putExtra("key_suggest_translation", "");
        i.putExtra("key_from_floating_window", false);

        i.setComponent(new ComponentName("com.google.android.apps.translate",
                "com.google.android.apps.translate.TranslateActivity"));
        context.startActivity(i);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(context, "Google translate app is not installed", Toast.LENGTH_SHORT).show();
        ex.printStackTrace();
    }
}

From source file:Main.java

/**
 * Drafts an email to the given email address, with the given subject line and message
 * @param context/*from  www. ja v  a 2 s. com*/
 * @param emailAddress
 * @param subject
 * @param message
 */
public static void emailDeveloper(Context context, String emailAddress, String subject, String message) {

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress });
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, message);

    context.startActivity(i);
}

From source file:Main.java

/**
 * Creates a intent with an image/*  w ww. ja v a  2s  .co  m*/
 *
 * @param image
 * @return
 */
public static Intent createIntentFromImage(File image) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    return share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
}

From source file:Main.java

public static void createDeskShortCut(Context cxt, String shortCutName, int icon, Class<?> cls) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    Parcelable ico = Intent.ShortcutIconResource.fromContext(cxt.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(cxt, cls);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    cxt.sendBroadcast(shortcutIntent);/* w  ww.ja v a 2s.c om*/
}

From source file:Main.java

public static void pauseMusic(Context context) {
    Intent freshIntent = new Intent();
    freshIntent.setAction("com.android.music.musicservicecommand.pause");
    freshIntent.putExtra("command", "pause");
    context.sendBroadcast(freshIntent);/*from w  w  w.  j a  v a2  s. c o  m*/
}

From source file:Main.java

public static void sendIntent(Context context, Class classes, String key, String value) {
    Intent intent = new Intent();
    intent.setClass(context, classes);//  ww w  . j  a v  a2s .c o  m
    intent.putExtra(key, value);
    context.startActivity(intent);
}

From source file:Main.java

public static void sendIntent(Context context, Class classes, String key, Parcelable value) {
    Intent intent = new Intent();
    intent.setClass(context, classes);//from   w w w  .ja v a  2s . co m
    intent.putExtra(key, value);
    context.startActivity(intent);
}

From source file:Main.java

public static Intent getSendIntent(Context context, String title, String text) {
    if (TextUtils.isEmpty(text))
        throw new IllegalArgumentException("text cannot be empty or null");
    if (TextUtils.isEmpty(title))
        throw new IllegalArgumentException("title cannot be empty or null");

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    sendIntent.setType("text/plain");
    return Intent.createChooser(sendIntent, title);
}

From source file:Main.java

public static void sendEmail(String email, Context context) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { email };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.setType(PLAIN_TEXT);/*  w w w. j  a v  a2 s . com*/
    context.startActivity(emailIntent);
}