Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:Main.java

/**
 * Lancia la finestra per la selezione di un gestore per la condivisione di un messaggio
 * (twitter, facebook, ....)./*from  w  w  w.j  av  a 2s  .co m*/
 * 
 * @param context
 * @param dialogTitle - Titolo della finestra di dialog (Share...)
 * @param subject - Subject (della email o titolo di twitter)
 * @param text - Testo del messaggio
 */
public static void share(Context context, String dialogTitle, String subject, String text) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(intent, dialogTitle));
}

From source file:Main.java

/**
 * Send an email via available mail activity
 * /*from   ww  w .ja  va  2 s .c om*/
 * @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:com.manning.androidhacks.hack004.util.LaunchEmailUtil.java

public static void launchEmailToIntent(Context context) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "feed@back.com" });
    intent.putExtra(Intent.EXTRA_SUBJECT, "[50AH] Feedback");
    intent.putExtra(Intent.EXTRA_TEXT, "Feedback:\n");
    context.startActivity(Intent.createChooser(intent, "Send feedback"));
}

From source file:Main.java

public static Intent getImageFromGalleryCamera(Context context) {
    // Determine Uri of camera image to save.
    File root = new File(
            Environment.getExternalStorageDirectory() + File.separator + "dianta/camera" + File.separator);
    root.mkdirs();// w w  w.  j ava  2  s  .  c o m
    String fname = "dianta-" + System.currentTimeMillis() + ".jpg";
    File sdImageMainDirectory = new File(root, fname);
    Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // camera
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager lPackageManager = context.getPackageManager();
    List<ResolveInfo> listCam = lPackageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo rInfo : listCam) {
        String packageName = rInfo.activityInfo.packageName;
        Intent lIntent = new Intent(captureIntent);
        lIntent.setComponent(new ComponentName(rInfo.activityInfo.packageName, rInfo.activityInfo.name));
        lIntent.setPackage(packageName);
        //save camera result to external storage
        lIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(lIntent);
    }

    //ugly hacks for camera helper
    lastCameraImageSaved = outputFileUri;

    // gallery
    Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_PICK);

    Intent chooserIntent = Intent.createChooser(galleryIntent, "Pilih Sumber");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:com.manning.androidhacks.hack036.util.LaunchEmailUtil.java

public static void launchEmailToIntent(Context context) {
    Intent msg = new Intent(Intent.ACTION_SEND);

    StringBuilder body = new StringBuilder("\n\n----------\n");
    body.append(EnvironmentInfoUtil.getApplicationInfo(context));

    msg.putExtra(Intent.EXTRA_EMAIL, context.getString(R.string.mail_support_feedback_to).split(", "));
    msg.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_support_feedback_subject));
    msg.putExtra(Intent.EXTRA_TEXT, body.toString());

    msg.setType("message/rfc822");
    context.startActivity(Intent.createChooser(msg, context.getString(R.string.pref_sendemail_title)));
}

From source file:com.theelix.libreexplorer.FileManager.java

/**
 * This method chooses the appropriate Apps and Open the file
 *
 * @param file The target file//from  www  . j  a  v  a  2  s.  c  o m
 */
public static void openFile(File file) {
    try {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        String mimeType = FileUtilties.getMimeType(uri);
        if (mimeType == null) {
            mimeType = "*/*";
        }
        intent.setDataAndType(uri, mimeType);
        mContext.startActivity(Intent.createChooser(intent, null));
    } catch (ActivityNotFoundException e) {
        //Activity is not found so App'll start an intent with generic Mimetype
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "*/*");
        mContext.startActivity(Intent.createChooser(intent, null));
    }

}

From source file:com.phunkosis.gifstitch.helpers.ShareHelper.java

public static void startShareLinkIntent(Activity activity, String url) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, activity.getResources().getString(R.string.share_link_body) + " " + url);
    intent.putExtra(Intent.EXTRA_SUBJECT, activity.getResources().getString(R.string.share_link_subject));
    intent.setType("text/plain");
    activity.startActivity(Intent.createChooser(intent, "Share "));
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending plain text and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param messageText the body text for the message to be shared
 * @param messageTitle the title/subject for the message to be shared, if supported by the target app
 */// ww  w .  j  av a 2  s .  c o  m
public static void shareText(Context context, String windowTitle, String messageText, String messageTitle) {
    Intent intentInvite = new Intent(Intent.ACTION_SEND);
    intentInvite.setType(HTTP.PLAIN_TEXT_TYPE);
    intentInvite.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intentInvite.putExtra(Intent.EXTRA_TEXT, messageText);
    context.startActivity(Intent.createChooser(intentInvite, windowTitle));
}

From source file:Main.java

/**
 * Returns an intent calling the android chooser. The chooser will provide apps, which listen to one of the following actions
 * {@link Intent#ACTION_GET_CONTENT} , {@link MediaStore#ACTION_IMAGE_CAPTURE}, {@link MediaStore#ACTION_VIDEO_CAPTURE},
 * {@link MediaStore.Audio.Media#RECORD_SOUND_ACTION}
 * //from w  ww .j a  va 2 s.  c  om
 * @return Intent that opens the app chooser.
 */
public static Intent getChooserIntent() {
    // GET_CONTENT Apps
    Intent getContentIntent = new Intent();
    getContentIntent.setAction(Intent.ACTION_GET_CONTENT);
    getContentIntent.setType("*/*");
    getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
    // ACTION_IMAGE_CAPTURE Apps
    Intent captureImageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // ACTION_VIDEO_CAPTURE Apps
    Intent captureVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // RECORD_SOUND_ACTION Apps
    Intent recordSoungIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    Intent finalIntent = Intent.createChooser(getContentIntent, "test");
    finalIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            new Intent[] { captureImageIntent, captureVideoIntent, recordSoungIntent });
    return finalIntent;
}

From source file:Main.java

/**
 * Intent chooser is customized to remove unwanted apps.
 * 1. FaceBook has bug where only links can be shared.
 * 2. Cannot share this type of content via Google Docs and Skype.
 *///from w  w  w.j a va 2s. com
public static void ShareResult(Context mContext, String mResult, String mTitle) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    List<ResolveInfo> resInfo = mContext.getPackageManager().queryIntentActivities(shareIntent, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
            targetedShareIntent.setType("text/plain");
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TITLE, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mResult);
            if (!packageName.toLowerCase().contains("com.facebook.katana")
                    && !packageName.toLowerCase().contains("com.google.android.apps.docs")
                    && !packageName.toLowerCase().contains("com.skype.raider")) {
                targetedShareIntent.setPackage(packageName);
                targetedShareIntents.add(targetedShareIntent);
            }
        }
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Send your result");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
        mContext.startActivity(chooserIntent);
    }
    return;
}