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: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//  w ww .  j  av  a  2 s . com
        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
        }
    });
}

From source file:com.esri.squadleader.view.SquadLeaderActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.add_layer:
        //Present Add Layer from Web dialog
        if (null == addLayerDialogFragment) {
            addLayerDialogFragment = new AddLayerDialogFragment();
            addLayerDialogFragment.setAddLayerFromFileRequestCode(ADD_LAYER_FROM_FILE);
        }/*w  w w.  j av a2s . co  m*/
        addLayerDialogFragment.show(getFragmentManager(), getString(R.string.add_layer_fragment_tag));
        return true;
    case R.id.add_feature:
        // Present Add Feature dialog
        if (null == addFeatureDialogFragment) {
            addFeatureDialogFragment = new AddFeatureDialogFragment();
        }
        addFeatureDialogFragment.show(getFragmentManager(), getString(R.string.add_feature_fragment_tag));
        return true;
    case R.id.clear_messages:
        //Present Clear Messages dialog
        if (null == clearMessagesDialogFragment) {
            clearMessagesDialogFragment = new ClearMessagesDialogFragment();
        }
        clearMessagesDialogFragment.show(getFragmentManager(), getString(R.string.clear_messages_fragment_tag));
        return true;
    case R.id.go_to_mgrs:
        //Present Go to MGRS dialog
        if (null == goToMgrsDialogFragment) {
            goToMgrsDialogFragment = new GoToMgrsDialogFragment();
        }
        goToMgrsDialogFragment.show(getFragmentManager(), getString(R.string.go_to_mgrs_fragment_tag));
        return true;
    case R.id.set_location_mode:
        //Present Set Location Mode dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.set_location_mode).setNegativeButton(R.string.cancel, null)
                .setSingleChoiceItems(
                        new String[] { getString(R.string.option_location_service),
                                getString(R.string.option_simulation_builtin),
                                getString(R.string.option_simulation_file) },
                        mapController.getLocationController().getMode() == LocationMode.LOCATION_SERVICE ? 0
                                : null == mapController.getLocationController().getGpxFile() ? 1 : 2,
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                clearDisplayStrings();
                                try {
                                    if (2 == which) {
                                        //Present file chooser
                                        Intent getContentIntent = FileUtils.createGetContentIntent();
                                        Intent intent = Intent.createChooser(getContentIntent, "Select a file");
                                        startActivityForResult(intent, REQUEST_CHOOSER);
                                    } else {
                                        mapController.getLocationController().setGpxFile(null, true);
                                        mapController.getLocationController()
                                                .setMode(0 == which ? LocationMode.LOCATION_SERVICE
                                                        : LocationMode.SIMULATOR, true);
                                        mapController.getLocationController().start();
                                    }
                                } catch (Exception e) {
                                    Log.d(TAG, "Couldn't set location mode", e);
                                } finally {
                                    dialog.dismiss();
                                }
                            }

                        });
        AlertDialog dialog = builder.create();
        dialog.show();
        return true;
    case R.id.settings:
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivityForResult(intent, SETTINGS_ACTIVITY);
        return true;
    case R.id.toggle_labels:
        item.setChecked(!item.isChecked());
        item.setIcon(item.isChecked() ? R.drawable.ic_action_labels : R.drawable.ic_action_labels_off);
        SharedPreferences prefs = getPreferences(MODE_PRIVATE);
        String key = getString(R.string.pref_labels);
        prefs.edit().putBoolean(key, item.isChecked()).commit();
        if (null != mil2525cController) {
            mil2525cController.setShowLabels(item.isChecked());
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.apps.gator.DisplayTranslationActivity.java

/**
 * Sends an email with a subject of Feedback.
 *//*from   w  w w . j av  a  2s.co m*/
private void openFeedback() {
    final Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("text/email");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "sudhirayrota@gmail.com" });
    email.putExtra(Intent.EXTRA_SUBJECT, "Feedback:Gator Translator:");
    email.putExtra(Intent.EXTRA_TEXT, "Dear Gator-Translator Development Team," + "");
    startActivity(Intent.createChooser(email, "Send Feedback:"));

}

From source file:com.apps.gator.DisplayTranslationActivity.java

/**
 * Sends an email with a subject of Report Error.
 *//*from   w  ww .j a  va  2s  . com*/
private void openReportError() {
    final Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("text/email");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "sudhirayrota@gmail.com" });
    email.putExtra(Intent.EXTRA_SUBJECT, "Report Error:Gator Translator:");
    email.putExtra(Intent.EXTRA_TEXT, "Dear Gator-Translator Development Team," + "");
    startActivity(Intent.createChooser(email, "Report Error:"));
}

From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java

@SuppressLint("NewApi")
protected void openFileInput(final ValueCallback<Uri> fileUploadCallbackFirst,
        final ValueCallback<Uri[]> fileUploadCallbackSecond) {
    if (mFileUploadCallbackFirst != null) {
        mFileUploadCallbackFirst.onReceiveValue(null);
    }//from   w ww.  j ava2s  .co m
    mFileUploadCallbackFirst = fileUploadCallbackFirst;

    if (mFileUploadCallbackSecond != null) {
        mFileUploadCallbackSecond.onReceiveValue(null);
    }
    mFileUploadCallbackSecond = fileUploadCallbackSecond;

    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType(mUploadableFileTypes);

    if (mFragment != null && mFragment.get() != null && Build.VERSION.SDK_INT >= 11) {
        mFragment.get().startActivityForResult(Intent.createChooser(i, getFileUploadPromptLabel()),
                mRequestCodeFilePicker);
    } else if (mActivity != null && mActivity.get() != null) {
        mActivity.get().startActivityForResult(Intent.createChooser(i, getFileUploadPromptLabel()),
                mRequestCodeFilePicker);
    }
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

/**
 * Allows user to send a GPX/KML file along with location, or location only
 * using a provider. 'Provider' means any application that can accept such
 * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth)
 */// www.  j  a v  a2  s. com
private void share() {

    try {

        final String locationOnly = getString(R.string.sharing_location_only);
        final File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder());
        if (gpxFolder.exists()) {

            File[] enumeratedFiles = Files.fromFolder(gpxFolder);

            Arrays.sort(enumeratedFiles, new Comparator<File>() {
                public int compare(File f1, File f2) {
                    return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
                }
            });

            List<String> fileList = new ArrayList<>(enumeratedFiles.length);

            for (File f : enumeratedFiles) {
                fileList.add(f.getName());
            }

            fileList.add(0, locationOnly);
            final String[] files = fileList.toArray(new String[fileList.size()]);

            new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files)
                    .positiveText(R.string.ok)
                    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
                        @Override
                        public boolean onSelection(MaterialDialog materialDialog, Integer[] integers,
                                CharSequence[] charSequences) {
                            List<Integer> selectedItems = Arrays.asList(integers);

                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("*/*");

                            if (selectedItems.size() <= 0) {
                                return false;
                            }

                            if (selectedItems.contains(0)) {

                                intent.setType("text/plain");

                                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                                if (Session.hasValidLocation()) {
                                    String bodyText = getString(R.string.sharing_googlemaps_link,
                                            String.valueOf(Session.getCurrentLatitude()),
                                            String.valueOf(Session.getCurrentLongitude()));
                                    intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                                    intent.putExtra("sms_body", bodyText);
                                    startActivity(
                                            Intent.createChooser(intent, getString(R.string.sharing_via)));
                                }
                            } else {

                                intent.setAction(Intent.ACTION_SEND_MULTIPLE);
                                intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
                                intent.setType("*/*");

                                ArrayList<Uri> chosenFiles = new ArrayList<>();

                                for (Object path : selectedItems) {
                                    File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]);
                                    Uri uri = Uri.fromFile(file);
                                    chosenFiles.add(uri);
                                }

                                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles);
                                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
                            }
                            return true;
                        }
                    }).show();

        } else {
            Dialogs.alert(getString(R.string.sorry), getString(R.string.no_files_found), this);
        }
    } catch (Exception ex) {
        LOG.error("Sharing problem", ex);
    }
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

private Response.Listener<JSONObject> createShortenerReqSuccessListener() {
    return new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject result) {
            try {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_SUBJECT, getSupportActionBar().getSubtitle());
                Object[] data = new Object[2];
                data[0] = getSupportActionBar().getSubtitle();
                data[1] = result.getString("id");
                intent.putExtra(Intent.EXTRA_TEXT, StringUtil.format("[DP]{0} - {1}", data));
                startActivity(Intent.createChooser(intent, getString(R.string.action_bar_share_with)));
                return;
            } catch (JSONException localJSONException) {
                LOGD(TAG, "Parse error");
            }/*  w  w w .j  a va2 s . c o m*/
        }
    };
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    ThingInfo _item = mThreadsAdapter.getItem(info.position);

    switch (item.getItemId()) {
    case Constants.VIEW_SUBREDDIT_CONTEXT_ITEM:
        new MyDownloadThreadsTask(_item.getSubreddit()).execute();
        return true;

    case Constants.SHARE_CONTEXT_ITEM:
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, _item.getUrl());
        try {/* ww w  . j  av a  2  s.c om*/
            startActivity(Intent.createChooser(intent, "Share Link"));
        } catch (android.content.ActivityNotFoundException ex) {
            if (Constants.LOGGING)
                Log.e(TAG, "Share Link", ex);
        }
        return true;

    case Constants.OPEN_IN_BROWSER_CONTEXT_ITEM:
        setLinkClicked(_item);
        Common.launchBrowser(this, _item.getUrl(), Util.createThreadUri(_item).toString(), false, true, true,
                mSettings.isSaveHistory());
        return true;

    case Constants.SAVE_CONTEXT_ITEM:
        new SaveTask(true, _item, mSettings, getApplicationContext()).execute();
        return true;

    case Constants.UNSAVE_CONTEXT_ITEM:
        new SaveTask(false, _item, mSettings, getApplicationContext()).execute();
        return true;

    case Constants.HIDE_CONTEXT_ITEM:
        new MyHideTask(true, _item, mSettings, getApplicationContext()).execute();
        return true;

    case Constants.UNHIDE_CONTEXT_ITEM:
        new MyHideTask(false, _item, mSettings, getApplicationContext()).execute();

    case Constants.DIALOG_VIEW_PROFILE:
        Intent i = new Intent(this, ProfileActivity.class);
        i.setData(Util.createProfileUri(_item.getAuthor()));
        startActivity(i);
        return true;

    default:
        return super.onContextItemSelected(item);
    }

}