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:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();/*  w  w w . j a v  a 2  s.com*/
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) MyfeedleCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.denel.facepatrol.MainActivity.java

public void ContactPhone(View view) {
    Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
    phoneIntent.setData(Uri.parse("tel:" + contact_phone));
    phoneIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivity(Intent.createChooser(phoneIntent, "Phone Number"));
    //finish();/* w ww  . j av a2s  .  c  o m*/
}

From source file:dentex.youtube.downloader.DashboardActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BugSenseHandler.leaveBreadcrumb("DashboardActivity_onCreate");
    //Utils.logger("v", "TotalRxBeforeTest: " + TotalRxBeforeTest, DEBUG_TAG);

    // Theme init
    Utils.themeInit(this);

    setContentView(R.layout.activity_dashboard);

    // Language init
    Utils.langInit(this);

    // Detect screen orientation
    int or = this.getResources().getConfiguration().orientation;
    isLandscape = (or == 2) ? true : false;

    sDashboard = DashboardActivity.this;

    if (da != null) {
        clearAdapterAndLists();//  w w w . j  a v  a2 s.  co m
    }

    countdown = 10;

    parseJson(this);
    updateProgressBars();
    buildList();

    lv = (ListView) findViewById(R.id.dashboard_list);

    da = new DashboardAdapter(itemsList, this);

    if (da.isEmpty()) {
        showEmptyListInfo(this);
    } else {
        lv.setAdapter(da);
    }

    /*Log.i(DEBUG_TAG, "ADML Maps:" +
     "\ndtMap:                 " + Maps.dtMap +
     "\nmDownloadPercentMap:   " + Maps.mDownloadPercentMap +
     "\nmDownloadSizeMap:      " + Maps.mDownloadSizeMap + 
     "\nmTotalSizeMap:         " + Maps.mTotalSizeMap);*/

    lv.setTextFilterEnabled(true);

    lv.setClickable(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (!isAnyAsyncInProgress) {
                currentItem = da.getItem(position); // in order to refer to the filtered item
                newClick = true;

                final boolean ffmpegEnabled = YTD.settings.getBoolean("enable_advanced_features", false);

                AlertDialog.Builder builder = new AlertDialog.Builder(boxThemeContextWrapper);
                builder.setTitle(currentItem.getFilename());

                if (currentItem.getStatus().equals(getString(R.string.json_status_completed))
                        || currentItem.getStatus().equals(getString(R.string.json_status_imported))) {

                    final boolean audioIsSupported = !currentItem.getAudioExt().equals("unsupported");
                    final File in = new File(currentItem.getPath(), currentItem.getFilename());

                    if (currentItem.getType().equals(YTD.JSON_DATA_TYPE_V)) {

                        // handle click on a **VIDEO** file entry
                        builder.setItems(R.array.dashboard_click_entries,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {

                                        switch (which) {
                                        case 0: // open
                                            BugSenseHandler.leaveBreadcrumb("video_open");
                                            Intent openIntent = new Intent(Intent.ACTION_VIEW);
                                            openIntent.setDataAndType(Uri.fromFile(in), "video/*");
                                            startActivity(Intent.createChooser(openIntent,
                                                    getString(R.string.open_chooser_title)));
                                            break;
                                        case 1: // extract audio only
                                            if (!isFfmpegRunning) {
                                                BugSenseHandler.leaveBreadcrumb("video_ffmpeg_extract");
                                                if (audioIsSupported) {
                                                    if (ffmpegEnabled) {
                                                        AlertDialog.Builder builder0 = new AlertDialog.Builder(
                                                                boxThemeContextWrapper);
                                                        LayoutInflater inflater0 = getLayoutInflater();
                                                        final View view0 = inflater0
                                                                .inflate(R.layout.dialog_audio_extr_only, null);

                                                        String type = null;
                                                        if (currentItem.getAudioExt().equals(".aac"))
                                                            type = aac;
                                                        if (currentItem.getAudioExt().equals(".ogg"))
                                                            type = ogg;
                                                        if (currentItem.getAudioExt().equals(".mp3"))
                                                            type = mp3;
                                                        //if (currentItem.getAudioExt().equals(".auto")) type = aac_mp3;

                                                        TextView info = (TextView) view0
                                                                .findViewById(R.id.audio_extr_info);
                                                        info.setText(getString(R.string.audio_extr_info)
                                                                + "\n\n" + type);

                                                        builder0.setView(view0).setPositiveButton("OK",
                                                                new DialogInterface.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(DialogInterface dialog,
                                                                            int id) {

                                                                        CheckBox cb0 = (CheckBox) view0
                                                                                .findViewById(R.id.rem_video_0);
                                                                        removeVideo = cb0.isChecked();

                                                                        Utils.logger("v",
                                                                                "Launching FFmpeg on: " + in
                                                                                        + "\n-> mode: extraction only"
                                                                                        + "\n-> remove video: "
                                                                                        + removeVideo,
                                                                                DEBUG_TAG);

                                                                        ffmpegJob(in, null, null);
                                                                    }
                                                                }).setNegativeButton(R.string.dialogs_negative,
                                                                        new DialogInterface.OnClickListener() {
                                                                            public void onClick(
                                                                                    DialogInterface dialog,
                                                                                    int id) {
                                                                                // cancel
                                                                            }
                                                                        });

                                                        secureShowDialog(builder0);
                                                    } else {
                                                        notifyFfmpegNotInstalled();
                                                    }
                                                } else {
                                                    notifyOpsNotSupported();
                                                }
                                            } else {
                                                notifyFfmpegIsAlreadyRunning();
                                            }

                                            break;
                                        case 2: // extract audio and convert to mp3
                                            if (!isFfmpegRunning) {
                                                BugSenseHandler.leaveBreadcrumb("video_ffmpeg_mp3");
                                                if (audioIsSupported) {
                                                    if (ffmpegEnabled) {
                                                        AlertDialog.Builder builder1 = new AlertDialog.Builder(
                                                                boxThemeContextWrapper);
                                                        LayoutInflater inflater1 = getLayoutInflater();

                                                        final View view1 = inflater1.inflate(
                                                                R.layout.dialog_audio_extr_mp3_conv, null);

                                                        builder1.setView(view1).setPositiveButton("OK",
                                                                new DialogInterface.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(DialogInterface dialog,
                                                                            int id) {

                                                                        final Spinner sp = (Spinner) view1
                                                                                .findViewById(R.id.mp3_spinner);
                                                                        String[] bitrateData = retrieveBitrateValueFromSpinner(
                                                                                sp);

                                                                        CheckBox cb1 = (CheckBox) view1
                                                                                .findViewById(R.id.rem_video_1);
                                                                        removeVideo = cb1.isChecked();

                                                                        Utils.logger("v",
                                                                                "Launching FFmpeg on: " + in
                                                                                        + "\n-> mode: conversion to mp3 from video file"
                                                                                        + "\n-> remove video: "
                                                                                        + removeVideo,
                                                                                DEBUG_TAG);

                                                                        ffmpegJob(in, bitrateData[0],
                                                                                bitrateData[1]);
                                                                    }
                                                                }).setNegativeButton(R.string.dialogs_negative,
                                                                        new DialogInterface.OnClickListener() {
                                                                            public void onClick(
                                                                                    DialogInterface dialog,
                                                                                    int id) {
                                                                                //
                                                                            }
                                                                        });

                                                        secureShowDialog(builder1);
                                                    } else {
                                                        notifyFfmpegNotInstalled();
                                                    }
                                                } else {
                                                    notifyOpsNotSupported();
                                                }
                                            } else {
                                                notifyFfmpegIsAlreadyRunning();
                                            }
                                        }
                                    }
                                });

                        secureShowDialog(builder);

                    } else if (currentItem.getType().equals(YTD.JSON_DATA_TYPE_A_E)
                            || currentItem.getType().equals(YTD.JSON_DATA_TYPE_A_M)) {

                        // handle click on a **AUDIO** file entry
                        builder.setItems(R.array.dashboard_click_entries_audio,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {

                                        switch (which) {
                                        case 0: // open
                                            BugSenseHandler.leaveBreadcrumb("audio_open");
                                            Intent openIntent = new Intent(Intent.ACTION_VIEW);
                                            openIntent.setDataAndType(Uri.fromFile(in), "audio/*");
                                            startActivity(Intent.createChooser(openIntent,
                                                    getString(R.string.open_chooser_title)));
                                            break;
                                        case 1: // convert to mp3
                                            if (!isFfmpegRunning) {
                                                if (ffmpegEnabled) {
                                                    BugSenseHandler.leaveBreadcrumb("audio_ffmpeg_mp3");
                                                    AlertDialog.Builder builder0 = new AlertDialog.Builder(
                                                            boxThemeContextWrapper);
                                                    LayoutInflater inflater0 = getLayoutInflater();
                                                    final View view2 = inflater0
                                                            .inflate(R.layout.dialog_audio_mp3_conv, null);

                                                    builder0.setView(view2).setPositiveButton("OK",
                                                            new DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void onClick(DialogInterface dialog,
                                                                        int id) {

                                                                    final Spinner sp = (Spinner) view2
                                                                            .findViewById(R.id.mp3_spinner_a);
                                                                    String[] bitrateData = retrieveBitrateValueFromSpinner(
                                                                            sp);

                                                                    CheckBox cb2 = (CheckBox) view2
                                                                            .findViewById(
                                                                                    R.id.rem_original_audio);
                                                                    removeAudio = cb2.isChecked();

                                                                    Utils.logger("v", "Launching FFmpeg on: "
                                                                            + in
                                                                            + "\n-> mode: conversion to mp3 from audio file"
                                                                            + "\n-> remove audio: "
                                                                            + removeAudio, DEBUG_TAG);

                                                                    ffmpegJob(in, bitrateData[0],
                                                                            bitrateData[1]);
                                                                }
                                                            }).setNegativeButton(R.string.dialogs_negative,
                                                                    new DialogInterface.OnClickListener() {
                                                                        public void onClick(
                                                                                DialogInterface dialog,
                                                                                int id) {
                                                                            //
                                                                        }
                                                                    });

                                                    secureShowDialog(builder0);
                                                } else {
                                                    notifyFfmpegNotInstalled();
                                                }
                                            } else {
                                                notifyFfmpegIsAlreadyRunning();
                                            }
                                        }
                                    }
                                });

                        secureShowDialog(builder);
                    }
                } /*else if (currentItem.getStatus().equals(getString(R.string.json_status_imported))) {
                   Utils.logger("v", "IMPORTED video clicked", DEBUG_TAG);
                           
                   // handle click on an  **IMPORTED VIDEO** entry
                   builder.setItems(R.array.dashboard_click_entries_imported, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                          
                   final File in = new File (currentItem.getPath(), currentItem.getFilename());
                           
                   switch (which) {
                   case 0: // open
                      Intent openIntent = new Intent(Intent.ACTION_VIEW);
                      openIntent.setDataAndType(Uri.fromFile(in), "video/*");
                      startActivity(Intent.createChooser(openIntent, getString(R.string.open_chooser_title)));
                      break;
                   }
                    }
                   });
                          
                   secureShowDialog(builder);
                  }*/
            }
        }
    });

    lv.setLongClickable(true);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

            if (!isAnyAsyncInProgress) {
                currentItem = da.getItem(position); // in order to refer to the filtered item

                int COPY = 0;
                int MOVE = 1;
                int RENAME = 2;
                int REDOWNLOAD = 3;
                int REMOVE = 4;
                int DELETE = 5;
                int PAUSERESUME = 6;

                int[] disabledItems = null;

                if (currentItem.getStatus().equals(getString(R.string.json_status_in_progress))
                        || currentItem.getStatus().equals(getString(R.string.json_status_paused))) {
                    // show: DELETE and  PAUSERESUME
                    disabledItems = new int[] { COPY, MOVE, RENAME, REDOWNLOAD, REMOVE };
                } else if (currentItem.getStatus().equals(getString(R.string.json_status_failed))) {
                    // check if the item has a real YouTube ID, otherwise it's an imported video.
                    if (currentItem.getYtId().length() == 11) {
                        // show: REMOVE and REDOWNLOAD
                        disabledItems = new int[] { COPY, MOVE, RENAME, DELETE, PAUSERESUME };
                    } else {
                        // show: REMOVE only
                        disabledItems = new int[] { COPY, MOVE, RENAME, REDOWNLOAD, DELETE, PAUSERESUME };
                    }

                } else if (currentItem.getStatus().equals(getString(R.string.json_status_imported)) ||
                //case for audio entries _completed but from _imported
                (currentItem.getStatus().equals(getString(R.string.json_status_completed))
                        && !(currentItem.getYtId().length() == 11))) {
                    // show: COPY, MOVE, RENAME, REMOVE and DELETE
                    disabledItems = new int[] { REDOWNLOAD, PAUSERESUME };
                } else if (currentItem.getStatus().equals(getString(R.string.json_status_completed))) {
                    // show: all items except PAUSERESUME
                    disabledItems = new int[] { PAUSERESUME };
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(boxThemeContextWrapper);
                builder.setTitle(currentItem.getFilename());

                final ArrayAdapter<CharSequence> cla = DashboardLongClickAdapter.createFromResource(
                        boxThemeContextWrapper, R.array.dashboard_long_click_entries,
                        android.R.layout.simple_list_item_1, disabledItems);

                builder.setAdapter(cla, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                        case 0:
                            BugSenseHandler.leaveBreadcrumb("copy");
                            copy(currentItem);
                            break;
                        case 1:
                            BugSenseHandler.leaveBreadcrumb("move");
                            move(currentItem);
                            break;
                        case 2:
                            BugSenseHandler.leaveBreadcrumb("rename");
                            rename(currentItem);
                            break;
                        case 3:
                            if (currentItem.getStatus().equals(getString(R.string.json_status_failed))) {
                                BugSenseHandler.leaveBreadcrumb("reDownload_RESTART");
                                reDownload(currentItem, "RESTART");
                            } else {
                                BugSenseHandler.leaveBreadcrumb("reDownload");
                                reDownload(currentItem, "-");
                            }
                            break;
                        case 4:
                            BugSenseHandler.leaveBreadcrumb("removeFromDashboard");
                            removeFromDashboard(currentItem);
                            break;
                        case 5:
                            BugSenseHandler.leaveBreadcrumb("delete");
                            delete(currentItem);
                            break;
                        case 6:
                            BugSenseHandler.leaveBreadcrumb("pauseresume");
                            pauseresume(currentItem);
                        }

                    }
                });

                secureShowDialog(builder);
            }

            return true;
        }
    });
}

From source file:pffy.mobile.flax.FlaxActivity.java

private boolean sendDetailsByIntent() {

    if (this.mExportFacts.equals("") || this.mExportFacts == null) {
        // do not send empty files
        return false;
    }// w  w w.j  a  va 2 s  .c om

    // boilerplate intent code
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, this.mExportFacts);
    sendIntent.setType(HTTP.PLAIN_TEXT_TYPE);
    startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.msg_shareto)));

    return true;
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

public void imageOpen(Fragment f, final int REQUEST_CAMERA, final int SELECT_FILE) {

    GeneralHelper.getInstance(MainActivity.this).setTempFragment(f);
    final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Add Photo!");
    builder.setItems(items, new DialogInterface.OnClickListener() {

        @Override/*from  w  ww . j av  a  2  s. c om*/
        public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Take Photo")) {

                java.io.File imageFile = new File(
                        (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/."
                                + Constants.APPNAME + "/" + System.currentTimeMillis() + ".jpeg"));

                PreferencesManager.setPreferenceByKey(MainActivity.this, "IMAGEWWC",
                        imageFile.getAbsolutePath());
                //
                imageFilePath = imageFile;
                imageFileUri = Uri.fromFile(imageFile);
                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
                startActivityForResult(i, REQUEST_CAMERA);

            } else if (items[item].equals("Choose from Library")) {
                if (Build.VERSION.SDK_INT < 19) {
                    Intent intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                } else {
                    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                }

            } else if (items[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

From source file:com.cw.litenote.operation.mail.MailPagesFragment.java

void sendEMail(String strEMailAddr, // eMail address
        String[] attachmentFileName, // attachment name
        String[] picFileNameArray) // attachment picture file name
{
    mAttachmentFileName = attachmentFileName;
    // new ACTION_SEND intent
    mEMailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); // for multiple attachments

    // set type//from  ww w  . java  2 s . c  o m
    mEMailIntent.setType("text/plain");//can select which APP will be used to send mail

    // open issue: cause warning for Key android.intent.extra.TEXT expected ArrayList
    String text_body = mContext.getResources().getString(R.string.eMail_body)// eMail text (body)
            + " " + Util.getStorageDirName(mContext) + " (UTF-8)" + Util.NEW_LINE + mEMailBodyString;

    // attachment: message
    List<String> filePaths = new ArrayList<String>();
    for (int i = 0; i < attachmentFileName.length; i++) {
        String messagePath = "file:///" + Environment.getExternalStorageDirectory().getPath() + "/"
                + Util.getStorageDirName(mContext) + "/" + attachmentFileName[i];// message file name
        filePaths.add(messagePath);
    }

    // attachment: pictures
    if (picFileNameArray != null) {
        for (int i = 0; i < picFileNameArray.length; i++) {
            filePaths.add(picFileNameArray[i]);
        }
    }

    ArrayList<Uri> uris = new ArrayList<Uri>();
    for (String file : filePaths) {
        Uri uri = Uri.parse(file);
        uris.add(uri);
    }

    mEMailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { strEMailAddr }) // eMail address
            .putExtra(Intent.EXTRA_SUBJECT, Util.getStorageDirName(mContext) + // eMail subject
                    " " + mContext.getResources().getString(R.string.eMail_subject))// eMail subject
            .putExtra(Intent.EXTRA_TEXT, text_body) // eMail body (open issue)
            .putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); // multiple eMail attachment

    Log.v(getClass().getSimpleName(), "attachment " + Uri.parse("file name is:" + attachmentFileName));

    getActivity().startActivityForResult(
            Intent.createChooser(mEMailIntent, getResources().getText(R.string.mail_chooser_title)),
            EMAIL_PAGES);
}

From source file:com.android.talkback.labeling.LabelManagerSummaryActivity.java

private void addExportCustomLabelClickListener() {
    final Button exportLabel = (Button) findViewById(R.id.export_labels);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        exportLabel.setVisibility(View.GONE);
        return;/* w  w  w  .j ava2 s .  com*/
    }

    exportLabel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            CustomLabelMigrationManager exporter = new CustomLabelMigrationManager(getApplicationContext());
            exporter.exportLabels(new CustomLabelMigrationManager.SimpleLabelMigrationCallback() {
                @Override
                public void onLabelsExported(File file) {
                    if (file == null) {
                        notifyLabelExportFailure();
                        return;
                    }

                    Uri uri = FileProvider.getUriForFile(getApplicationContext(), FILE_AUTHORITY, file);
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    shareIntent.setType("application/json");

                    String activityTitle = getResources().getString(R.string.label_choose_app_to_export);
                    startActivity(Intent.createChooser(shareIntent, activityTitle));
                }

                @Override
                public void onFail() {
                    notifyLabelExportFailure();
                }
            });
            return;
        }
    });
}

From source file:com.example.linhdq.test.documents.viewing.single.DocumentActivity.java

void shareText() {
    String shareBody = getPlainDocumentText();
    if (shareBody == null) {
        Toast.makeText(DocumentActivity.this, R.string.empty_document, Toast.LENGTH_LONG).show();
        return;//w  w  w .ja  v a2s  .  c o m
    }

    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.share_subject);
    sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_chooser_title)));
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

@SuppressLint("NewApi")
@Override//www . j  ava  2 s . co m
public boolean onContextItemSelected(MenuItem item) {
    Log.v(TAG, "onContextItemSelected");

    WebView.HitTestResult result = webView.getHitTestResult();
    Log.d(TAG, "result: " + result.getExtra());
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);

    switch (item.getItemId()) {
    case R.id.itemSaveImage:
    case R.id.itemSaveLink:

        try {
            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            Request request = new Request(Uri.parse(result.getExtra()));
            dm.enqueue(request);
        } catch (Exception e) {
            Toast.makeText(this, "sBrowser - Error saving...", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "Erro Downloading: " + e);
        }
        break;

    case R.id.itemCopyLink:

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(result.getExtra());
        } else {
            android.content.ClipboardManager newClipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("label", result.getExtra());
            newClipboard.setPrimaryClip(clip);
        }

        break;

    case R.id.itemShareLink:

        try {
            sharingIntent.setType("text/html");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing link: " + e);
        }

        break;

    case R.id.itemShareImage:

        try {
            sharingIntent.setType("image/*");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share image using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing Image: " + e);
        }

        break;
    }

    return super.onContextItemSelected(item);
}

From source file:com.brq.wallet.activity.receive.ReceiveCoinsActivity.java

public void shareRequest(View view) {
    Intent s = new Intent(android.content.Intent.ACTION_SEND);
    s.setType("text/plain");
    if (CurrencyValue.isNullOrZero(_amount)) {
        s.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.bitcoin_address_title));
        s.putExtra(Intent.EXTRA_TEXT, getBitcoinAddress());
        startActivity(Intent.createChooser(s, getResources().getString(R.string.share_bitcoin_address)));
    } else {/*from   w ww.ja  v a2s  .c  o m*/
        s.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.payment_request));
        s.putExtra(Intent.EXTRA_TEXT, getPaymentUri());
        startActivity(Intent.createChooser(s, getResources().getString(R.string.share_payment_request)));
    }
}