Example usage for android.content Intent EXTRA_INITIAL_INTENTS

List of usage examples for android.content Intent EXTRA_INITIAL_INTENTS

Introduction

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

Prototype

String EXTRA_INITIAL_INTENTS

To view the source code for android.content Intent EXTRA_INITIAL_INTENTS.

Click Source Link

Document

A Parcelable[] of Intent or android.content.pm.LabeledIntent objects as set with #putExtra(String,Parcelable[]) of additional activities to place a the front of the list of choices, when shown to the user with a #ACTION_CHOOSER .

Usage

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void getNewPicture(boolean checkPermission) {
    if (checkPermission) {
        askCameraPermission(false, new SafeRunnable() {
            @Override/*from  w  w  w .j av  a 2s  .  c  om*/
            protected void safeRun() throws Exception {
                getNewPicture(false);
            }
        });
        return;
    }

    if (!setupUploadFile("jpg", true)) {
        return;
    }

    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedFile);
    galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    galleryIntent.setType("image/*");

    final Intent chooserIntent = Intent.createChooser(galleryIntent,
            mActivity.getString(R.string.select_source));

    if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            && mMainService.isPermitted(Manifest.permission.CAMERA)) {
        Intent cameraIntent = ActivityUtils.buildTakePictureIntent(mActivity, mUriSavedFile, Facing.BACK);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { cameraIntent });
    }

    mActivity.startActivityForResult(chooserIntent, PICK_IMAGE);
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void getNewVideo(boolean checkPermission) {
    if (checkPermission) {
        askCameraPermission(true, new SafeRunnable() {
            @Override//from  w  ww  .  j a  va  2s .c  om
            protected void safeRun() throws Exception {
                getNewVideo(false);
            }
        });
        return;
    }

    if (!setupUploadFile("mp4", true)) {
        return;
    }

    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedFile);
    galleryIntent.setType(AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4);

    final Intent chooserIntent = Intent.createChooser(galleryIntent,
            mActivity.getString(R.string.select_source));
    if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            && mMainService.isPermitted(Manifest.permission.CAMERA)) {
        Intent cameraIntent = ActivityUtils.buildMakeVideoIntent(mActivity, mUriSavedFile);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { cameraIntent });
    }

    mActivity.startActivityForResult(chooserIntent, PICK_VIDEO);
}

From source file:co.taqat.call.ChatFragment.java

private void pickImage() {
    List<Intent> cameraIntents = new ArrayList<Intent>();
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(),
            getString(R.string.temp_photo_name_with_date).replace("%s",
                    String.valueOf(System.currentTimeMillis())));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);/*from  w w  w . j ava 2s  .c o m*/

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

    Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    startActivityForResult(chooserIntent, ADD_PHOTO);
}

From source file:com.aimfire.main.MainActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"//from  w w w  .  jav a2 s .co  m
 *
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 *
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page.
 *
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first
 * then paste the link
 */
private void inviteFriend() {
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_INVITE, null);

    Resources resources = getResources();

    /*
     * construct link
     */
    String appLink = resources.getString(R.string.app_store_link);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    emailSubject = resources.getString(R.string.emailSubjectInviteFriend);
    emailText = resources.getString(R.string.emailBodyInviteFriend) + appLink;
    twitterText = resources.getString(R.string.emailBodyInviteFriend) + appLink + ", "
            + resources.getString(R.string.app_hashtag);

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 *
                 * Warning: Facebook IGNORES our text. They say "These fields are intended
                 * for users to express themselves. Pre-filling these fields erodes the
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't
                 * allow the user to choose how they want to share. We can also make a
                 * custom landing page, and the link will show the <meta content ="...">
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

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

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(appLink));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

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

From source file:me.trashout.fragment.TrashReportOrEditFragment.java

private void createCameraIntentChooser() {
    List<Intent> allIntents = new ArrayList<>();
    PackageManager packageManager = getActivity().getPackageManager();
    allIntents.addAll(getCameraIntents(getActivity(), packageManager));
    Intent target;/*from  w w  w. j av  a 2  s.c  om*/
    if (allIntents.isEmpty()) {
        target = new Intent();
    } else {
        target = allIntents.get(allIntents.size() - 1);
        allIntents.remove(allIntents.size() - 1);
    }

    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());

    Intent chooserIntent = Intent.createChooser(target,
            getString(com.theartofdev.edmodo.cropper.R.string.pick_image_intent_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));
    getActivity().startActivityForResult(chooserIntent, CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE);
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("File/*");

    /*try {/*from  ww  w  .j a v a 2  s.co  m*/
    startActivityForResult(intent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
    // Potentially direct the user to the Market with a Dialog
    Toast.makeText(this, "Please install a File Manager.",
            Toast.LENGTH_SHORT).show();
    }*/
    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
    // if you want any file type, you can skip next line
    // sIntent.putExtra("CONTENT_TYPE", "*/*");
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (getPackageManager().resolveActivity(sIntent, 0) != null) {
        // it is device with samsung file manager
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    try {
        startActivityForResult(chooserIntent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java

/**
 * Show the location on a map./*w  w  w.j  a  v  a2  s.c  o m*/
 * Intent filtering code based off answer by "gumberculese";
 * http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name
 */
protected void showMap() {
    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    mapIntent.setData(location.getUri());
    //if (mapIntent.resolveActivity(getPackageManager()) != null)
    //{
    //    startActivity(mapIntent);
    //}

    String myPackage = "com.forrestguice.suntimeswidget";
    List<ResolveInfo> info = getPackageManager().queryIntentActivities(mapIntent, 0);
    List<Intent> geoIntents = new ArrayList<Intent>();

    if (!info.isEmpty()) {
        for (ResolveInfo resolveInfo : info) {
            String packageName = resolveInfo.activityInfo.packageName;
            if (!TextUtils.equals(packageName, myPackage)) {
                Intent geoIntent = new Intent(Intent.ACTION_VIEW);
                geoIntent.setPackage(packageName);
                geoIntent.setData(location.getUri());
                geoIntents.add(geoIntent);
            }
        }
    }

    if (geoIntents.size() > 0) {
        Intent chooserIntent = Intent.createChooser(geoIntents.remove(0),
                getString(R.string.configAction_mapLocation_chooser));
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                geoIntents.toArray(new Parcelable[geoIntents.size()]));
        startActivity(chooserIntent);

    } else {
        Toast noAppError = Toast.makeText(this, getString(R.string.configAction_mapLocation_noapp),
                Toast.LENGTH_LONG);
        noAppError.show();
    }
}

From source file:me.tb.player.SkeletonActivity.java

public void onShareClick() {
    Resources resources = getResources();
    String type = "image/*";
    String mediaPath = Environment.getExternalStorageDirectory() + "/game_icon1.png";

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);/* w  w  w  .  j ava  2s  . c  o m*/

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_TEXT,
            "Download in Google Play Store\nhttps://play.google.com/store/apps/details?id=me.tb.player");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Play Word Bandit - Multiplayer");
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    emailIntent.setType(type);

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

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("com.google.android.gm")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook.katana")
                || packageName.contains("com.instagram.android")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(type);
            // Add the URI and the caption to the Intent.
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            if (packageName.contains("twitter") || packageName.contains("instagram")) {
                intent.putExtra(Intent.EXTRA_TEXT, shareMessageCombo
                        + "\nDownload now https://play.google.com/store/apps/details?id=me.tb.player");
            }
            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

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

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

private void sendFiles(final ArrayList<Uri> filesToSend) {
    // send files in a separate task without a dialog so we don't leave the previous progress dialog behind on
    // screen rotation - this is a bit of a hack, but it works
    runImmediateBackgroundTask(new BackgroundRunnable() {
        @Override//from www  . j a  v a  2 s.  c om
        public int getTaskId() {
            return 0;
        }

        @Override
        public boolean getShowDialog() {
            return false;
        }

        @Override
        public void run() {
            if (filesToSend == null || filesToSend.size() <= 0) {
                return;
            }

            // ensure files are accessible to send - bit of a last-ditch effort for when temp is on internal storage
            for (Uri fileUri : filesToSend) {
                IOUtilities.setFullyPublic(new File(fileUri.getPath()));
            }

            // also see: http://stackoverflow.com/questions/2344768/
            // could use application/smil+xml (or html), or video/quicktime, but then there's no bluetooth option
            final Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            sendIntent.setType(getString(R.string.export_mime_type));
            sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);

            final Intent chooserIntent = Intent.createChooser(sendIntent,
                    getString(R.string.export_narrative_title));

            // an extra activity at the start of the list that moves exported files to SD, but only if SD available
            if (IOUtilities.externalStorageIsWritable()) {
                final Intent targetedShareIntent = new Intent(MediaPhoneActivity.this,
                        SaveNarrativeActivity.class);
                targetedShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                targetedShareIntent.setType(getString(R.string.export_mime_type));
                targetedShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { targetedShareIntent });
            }

            startActivity(chooserIntent); // single task mode; no return value given
        }
    });
}