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 void shareText(Context ctx, String title, String text) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    //intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    ctx.startActivity(Intent.createChooser(intent, title));
    /* List<ResolveInfo> ris = getShareTargets(ctx);
     if (ris != null && ris.size() > 0) {
     ctx.startActivity(Intent.createChooser(intent, title));
     }*///from   w ww. ja  v a2 s.c o  m
}

From source file:Main.java

public static Intent makeIntent(Context context, Class<?> classInstance, Map<String, Object> param) {
    Intent intent = new Intent(context, classInstance);
    for (Object obj : param.keySet().toArray()) {
        String key = (String) obj;
        intent.putExtra(key, (String) param.get(key));
    }/*ww  w .j  ava 2 s.c  o  m*/

    return intent;

}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String bundleName, Bundle bundle) {
    if (context == null) {
        return;/*from   w ww.j a  v a 2  s .com*/
    }
    Intent intent = new Intent();
    intent.setAction(filter);
    intent.putExtra(bundleName, bundle);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void sendIntent(Context context, Class classes, String key, ArrayList<? extends Parcelable> value,
        String anotherKey, String anotherValue) {
    Intent intent = new Intent();
    intent.setClass(context, classes);/* ww w . jav a2 s . c o m*/
    intent.putParcelableArrayListExtra(key, value);
    intent.putExtra(anotherKey, anotherValue);
    context.startActivity(intent);
}

From source file:Main.java

public static void addToCalendar(Activity context, Long beginTime, String title) {
    ContentResolver cr = context.getContentResolver();

    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    Long time = new Date(beginTime).getTime();
    ContentUris.appendId(builder, time - 10 * 60 * 1000);
    ContentUris.appendId(builder, time + 10 * 60 * 1000);

    String[] projection = new String[] { "title", "begin" };
    Cursor cursor = cr.query(builder.build(), projection, null, null, null);

    boolean exists = false;
    if (cursor != null) {
        while (cursor.moveToNext()) {
            if ((time == cursor.getLong(1)) && title.equals(cursor.getString(0))) {
                exists = true;//w ww .ja v  a 2 s. co  m
            }
        }
    }

    if (!exists) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", time);
        intent.putExtra("allDay", false);
        intent.putExtra("endTime", time + 60 * 60 * 1000);
        intent.putExtra("title", title);
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "Event already exist!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static void broadcast(Context context, String what, Map<String, String> params) {
    Intent intent = new Intent(what);
    if (params != null) {
        Set<String> keys = params.keySet();
        for (String string : keys) {
            intent.putExtra(string, params.get(string));
        }//from   www.  ja  v  a2s  .  c om
    }
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void startShareIntentActivity(Activity activity, String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    activity.startActivity(intent);//w  w w  .  j  a v a2s. c o  m
}

From source file:Main.java

public static void broadcast(Context context, String action, Map<String, String> params) {
    Intent intent = new Intent(action);
    if (params != null) {
        Set<String> keys = params.keySet();
        for (String string : keys) {
            intent.putExtra(string, params.get(string));
        }// ww w .  ja  va2 s.  c  o m
    }
    context.sendBroadcast(intent);
}

From source file:Main.java

static void passDownload(String linkToDownload, String SAVE, String notificationTitle, String fileName,
        String fileType, String userName, Context mContext) {
    Intent downloadIntent = new Intent();
    downloadIntent.setPackage("com.ihelp101.instagram");
    downloadIntent.setAction("com.ihelp101.instagram.PASS");
    downloadIntent.putExtra("URL", linkToDownload);
    downloadIntent.putExtra("SAVE", SAVE);
    downloadIntent.putExtra("Notification", notificationTitle);
    downloadIntent.putExtra("Filename", fileName);
    downloadIntent.putExtra("Filetype", fileType);
    downloadIntent.putExtra("User", userName);
    mContext.startService(downloadIntent);
}

From source file:Main.java

public static void openMailChooser(Context context, String text, String[] mails, String subject) {
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_TEXT, text);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, "");

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);
            if (packageName.contains(PACKAGE_MMS)) {
                intent.putExtra("subject", subject);
                intent.putExtra("sms_body", text);
                intent.putExtra("address", mails[0]);
                intent.setType(INTENT_TYPE_MSG);
            } else if (packageName.contains(PACKAGE_GMAIL)) {
                intent.putExtra(Intent.EXTRA_TEXT, text);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_EMAIL, mails);
                intent.setType(INTENT_TYPE_MSG);
            }/*from   w w w . j  a v  a  2 s  . co m*/

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);
}