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:ca.rmen.android.networkmonitor.app.dbops.ui.Share.java

/**
 * Run the given file export, then bring up the chooser intent to share the exported file.
 * The progress will be displayed in a progress dialog on the given activity.
 *///w  w  w .  j  a  v  a  2  s  .  com
private static void shareFile(final FragmentActivity activity, final FileExport fileExport) {
    Log.v(TAG, "shareFile " + fileExport);

    Bundle bundle = new Bundle(1);
    bundle.putString(DBOpAsyncTask.EXTRA_DIALOG_MESSAGE,
            activity.getString(R.string.export_progress_preparing_export));
    new DBOpAsyncTask<File>(activity, fileExport, bundle) {

        @Override
        protected File doInBackground(Void... params) {
            Log.v(TAG, "doInBackground");
            File file = null;
            if (fileExport != null) {
                if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                    return null;
                file = super.doInBackground(params);
                if (file == null)
                    return null;
            }

            String reportSummary = SummaryExport.getSummary(activity);
            // Bring up the chooser to share the file.
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.export_subject_send_log));

            String dateRange = SummaryExport.getDataCollectionDateRange(activity);

            String messageBody = activity.getString(R.string.export_message_text, dateRange);
            if (file != null) {
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
                sendIntent.setType("message/rfc822");
                messageBody += activity.getString(R.string.export_message_text_file_attached);
            } else {
                sendIntent.setType("text/plain");
            }
            messageBody += reportSummary;
            sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);

            activity.startActivity(
                    Intent.createChooser(sendIntent, activity.getResources().getText(R.string.action_share)));
            return file;
        }

        @Override
        protected void onPostExecute(File result) {
            Log.v(TAG, "onPostExecute");
            // Show a toast if we failed to export a file.
            if (fileExport != null && result == null)
                Toast.makeText(activity, R.string.export_error_sdcard_unmounted, Toast.LENGTH_LONG).show();
            super.onPostExecute(result);
        }
    }.execute();
}

From source file:com.callrecorder.android.RecordingsAdapter.java

private void sendMail(String fileName) {
    DocumentFile file = FileHelper.getStorageFile(context).findFile(fileName);
    Uri uri = FileHelper.getContentUri(context, file.getUri());

    Intent sendIntent = new Intent(Intent.ACTION_SEND)
            .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_subject))
            .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.mail_body))
            .putExtra(Intent.EXTRA_STREAM, uri).setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .setType("audio/3gpp");

    context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.send_mail)));
}

From source file:co.nerdart.ourss.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        String starredList = "";
        Cursor cursor = mEntriesCursorAdapter.getCursor();
        if (cursor != null && !cursor.isClosed()) {
            int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
            int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
            if (cursor.moveToFirst()) {
                do {
                    starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                } while (cursor.moveToNext());
            }/*from w w  w.  ja va 2 s . c  o  m*/
            startActivity(Intent.createChooser(
                    new Intent(Intent.ACTION_SEND)
                            .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_favorites_title))
                            .putExtra(Intent.EXTRA_TEXT, starredList).setType(Constants.MIMETYPE_TEXT_PLAIN),
                    getString(R.string.menu_share)));
        }
        return true;
    }
    case R.id.menu_refresh: {
        if (!FetcherService.isRefreshingFeeds) {
            getActivity().startService(
                    new Intent(getActivity(), FetcherService.class).setAction(Constants.ACTION_REFRESH_FEEDS));
        }
        return true;
    }
    case R.id.menu_all_read: {
        mEntriesCursorAdapter.markAllAsRead();
        return true;
    }
    case R.id.menu_hide_read: {
        if (!PrefUtils.getBoolean(PrefUtils.SHOW_READ, true)) {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, true);
            item.setTitle(R.string.context_menu_hide_read).setIcon(R.drawable.hide_reads);
        } else {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, false);
            item.setTitle(R.string.context_menu_show_read).setIcon(R.drawable.view_reads);
        }
        return true;
    }
    case R.id.menu_settings: {
        startActivity(new Intent(getActivity(), GeneralPrefsActivity.class));
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.pixellostudio.qqdroid.BaseQuote.java

public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case 1://w  ww  .j a  v a2s  .c  om
        AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

        Spanned quote = Html.fromHtml((String) view.getAdapter().getItem(menuInfo.position));

        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_TEXT,
                getBaseContext().getText(R.string.quotefrom) + " " + name + " : " + quote);
        i.setType("text/plain");
        startActivity(Intent.createChooser(i, this.getText(R.string.share)));

        break;
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:mobisocial.musubi.ui.fragments.ChooseImageDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setTitle("Choose an Image...")
            .setItems(new String[] { "From Camera", "From Gallery" }, new DialogInterface.OnClickListener() {
                @SuppressWarnings("deprecation")
                @Override//from  w ww. java2 s .com
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case 0:
                        final Activity activity = getActivity();
                        Toast.makeText(activity, "Loading camera...", Toast.LENGTH_SHORT).show();
                        ((InstrumentedActivity) activity)
                                .doActivityForResult(new PhotoTaker(activity, new PhotoTaker.ResultHandler() {
                                    @Override
                                    public void onResult(Uri imageUri) {
                                        Log.d(getClass().getSimpleName(), "Updating thumbnail...");

                                        try {
                                            UriImage image = new UriImage(activity, imageUri);
                                            byte[] data = image.getResizedImageData(512, 512,
                                                    PictureObj.MAX_IMAGE_SIZE / 2);
                                            // profile
                                            Bitmap sourceBitmap = BitmapFactory.decodeByteArray(data, 0,
                                                    data.length);
                                            int width = sourceBitmap.getWidth();
                                            int height = sourceBitmap.getHeight();
                                            int cropSize = Math.min(width, height);
                                            Bitmap cropped = Bitmap.createBitmap(sourceBitmap, 0, 0, cropSize,
                                                    cropSize);
                                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                            cropped.compress(Bitmap.CompressFormat.JPEG, 90, baos);
                                            cropped.recycle();
                                            sourceBitmap.recycle();

                                            Bundle bundle = new Bundle();
                                            bundle.putByteArray(EXTRA_THUMBNAIL, baos.toByteArray());
                                            Intent res = new Intent();
                                            res.putExtras(bundle);
                                            getTargetFragment().onActivityResult(REQUEST_PROFILE_PICTURE,
                                                    Activity.RESULT_OK, res);
                                        } catch (Throwable t) {
                                            Log.e("ViewProfile", "failed to generate thumbnail of profile", t);
                                            Toast.makeText(activity,
                                                    "Profile picture capture failed.  Try again.",
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }, 200, false));
                        break;
                    case 1:
                        Intent gallery = new Intent(Intent.ACTION_GET_CONTENT);
                        gallery.setType("image/*");
                        // god damn fragments.
                        getTargetFragment().startActivityForResult(Intent.createChooser(gallery, null),
                                REQUEST_GALLERY_THUMBNAIL);
                        break;
                    }
                }
            }).create();
}

From source file:com.dwdesign.gallery3d.app.ImageViewerGLActivity.java

@Override
public void onClick(final View view) {
    final Uri uri = getIntent().getData();
    switch (view.getId()) {
    case R.id.close: {
        onBackPressed();/* w  w w  .j  a  v  a  2  s.com*/
        break;
    }
    case R.id.refresh_stop_save: {
        final LoaderManager lm = getSupportLoaderManager();
        if (!mImageLoaded && !lm.hasRunningLoaders()) {
            loadImage();
        } else if (!mImageLoaded && lm.hasRunningLoaders()) {
            stopLoading();
        } else if (mImageLoaded) {
            new SaveImageTask(this, mImageFile).execute();
        }
        break;
    }
    case R.id.share: {
        if (uri == null) {
            break;
        }
        final Intent intent = new Intent(Intent.ACTION_SEND);
        if (mImageFile != null && mImageFile.exists()) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile));
        } else {
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
        }
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case R.id.open_in_browser: {
        if (uri == null) {
            break;
        }
        final String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                startActivity(intent);
            } catch (final ActivityNotFoundException e) {
                // Ignore.
            }
        }
        break;
    }
    }
}

From source file:com.dm.material.dashboard.candybar.fragments.dialog.AboutFragment.java

@Override
public void onClick(View view) {
    int id = view.getId();
    Intent intent = null;//ww  w .j  a  v  a2 s  . c  o m
    if (id == R.id.email) {
        try {
            final Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                    getActivity().getResources().getString(R.string.about_email), null));
            email.putExtra(Intent.EXTRA_SUBJECT, (getActivity().getResources().getString(R.string.app_name)));
            getActivity().startActivity(
                    Intent.createChooser(email, getActivity().getResources().getString(R.string.email_client)));
            dismiss();
        } catch (ActivityNotFoundException e) {
            Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
        }
        return;
    } else if (id == R.id.link1) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_link_1_url)));
    } else if (id == R.id.link2) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_link_2_url)));
    } else if (id == R.id.dev_link1) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_dashboard_dev_github_url)));
    } else if (id == R.id.dev_link2) {
        intent = new Intent(Intent.ACTION_VIEW, Uri
                .parse(getActivity().getResources().getString(R.string.about_dashboard_dev_google_plus_url)));
    }

    try {
        getActivity().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
}

From source file:com.abiansoftware.lib.reader.AbianReaderItemActivity.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(this, AbianReaderActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);/*from  w  w  w.  j  a v a 2  s .  c  om*/

        return true;
    } else if (item.getItemId() == SHARE_ITEM_ID) {
        String shareMessage = getString(R.string.share_message);
        String shareTitle = getString(R.string.share_title);

        AbianReaderItem targetItem = AbianReaderApplication.getData().getItemNumber(m_currentPage);

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, targetItem.getLink());
        startActivity(Intent.createChooser(sharingIntent, shareTitle));

        return true;
    } else if (item.getItemId() == OPEN_BROWSER_ITEM_ID) {
        AbianReaderItem targetItem = AbianReaderApplication.getData().getItemNumber(m_currentPage);

        String url = targetItem.getLink();
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.asksven.betterbatterystats.ShareDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    //ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light_Dialog);
    ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), BaseActivity.getTheme(getActivity()));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean saveAsText = sharedPrefs.getBoolean("save_as_text", true);
    boolean saveAsJson = sharedPrefs.getBoolean("save_as_json", false);
    boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
    boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);

    final String m_refFromName = "";
    final String m_refToName = "";

    if (saveAsText) {
        selectedSaveActions.add(0);// w w w  .  ja  va 2  s. c o  m
    }
    if (saveAsJson) {
        selectedSaveActions.add(1);
    }
    if (saveLogcat) {
        selectedSaveActions.add(2);
    }
    if (saveDmesg) {
        selectedSaveActions.add(3);
    }

    builder.setTitle("Title");

    builder.setMultiChoiceItems(R.array.saveAsLabels,
            new boolean[] { saveAsText, saveAsJson, saveLogcat, saveDmesg },
            new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    if (isChecked) {
                        // If the user checked the item, add it to the
                        // selected items
                        selectedSaveActions.add(which);
                    } else if (selectedSaveActions.contains(which)) {
                        // Else, if the item is already in the array,
                        // remove it
                        selectedSaveActions.remove(Integer.valueOf(which));
                    }
                }
            })
            // Set the action buttons
            .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    ArrayList<Uri> attachements = new ArrayList<Uri>();

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity());
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity());

                    Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        attachements.add(reading.writeToFileText(getActivity()));
                    }
                    // save as JSON if selected
                    if (selectedSaveActions.contains(1)) {
                        attachements.add(reading.writeToFileJson(getActivity()));
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(2)) {
                        attachements.add(StatsProvider.getInstance(getActivity()).writeLogcatToFile());
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(3)) {
                        attachements.add(StatsProvider.getInstance(getActivity()).writeDmesgToFile());
                    }

                    if (!attachements.isEmpty()) {
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
                        shareIntent.setType("text/*");
                        startActivity(Intent.createChooser(shareIntent, "Share info to.."));
                    }
                }
            }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity());
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity());

                    Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        reading.writeToFileText(getActivity());
                    }
                    // save as JSON if selected
                    if (selectedSaveActions.contains(1)) {
                        reading.writeToFileJson(getActivity());
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(2)) {
                        StatsProvider.getInstance(getActivity()).writeLogcatToFile();
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(3)) {
                        StatsProvider.getInstance(getActivity()).writeDmesgToFile();
                    }

                }
            }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:cc.metapro.openct.allclasses.ExcelDialog.java

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {//from   w  ww .ja va  2s.  com
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(getActivity(), R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}