List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:ca.ualberta.cmput301.t03.inventory.AddItemView.java
/** * When the upload photos button is clicked an alert dialog will get created asking the * user if they want to upload a photo or take a photo, either option will result in a returned * bitmap which is handled in onActivityResult. * * Code used:/* ww w .j av a 2 s . c o m*/ * http://stackoverflow.com/questions/27874038/how-to-make-intent-chooser-for-camera-or-gallery-application-in-android-like-wha */ private void onUploadPhotosButtonClicked() { final CharSequence[] items = { "Take A Photo", "Choose Photo from Gallery" }; AlertDialog.Builder builder = new AlertDialog.Builder(AddItemView.this); builder.setTitle("Attach Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } else if (item == 1) { 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); } } }); builder.show(); }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described email using the selected application * * @param recipientEmail the recipient's email address * @param subjectText the subject line of the message * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param restrictToPackage an application's package name to restricted the selection to * @param context a context reference/*from w ww . j a v a 2 s. c o m*/ * @throws Exception if there was an error trying to launch the email application */ public static void sendMail(final String recipientEmail, final String subjectText, final String bodyText, final int captionRes, final String restrictToPackage, final Context context) throws Exception { final String uriString = "mailto:" + Uri.encode(recipientEmail) + "?subject=" + Uri.encode(subjectText) + "&body=" + Uri.encode(bodyText); final Uri uri = Uri.parse(uriString); final Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setData(uri); if (restrictToPackage != null && restrictToPackage.length() > 0) { emailIntent.setPackage(restrictToPackage); if (context != null) { // launch the target app directly context.startActivity(emailIntent); } } else { if (context != null) { // offer a selection of all applications that can handle the email Intent context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes))); } } }
From source file:com.codebutler.farebot.fragment.CardsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); try {/*from w w w . j av a 2s.co m*/ int itemId = item.getItemId(); switch (itemId) { case R.id.import_file: Intent target = new Intent(Intent.ACTION_GET_CONTENT); target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory())); target.setType("*/*"); startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)), REQUEST_SELECT_FILE); return true; case R.id.import_clipboard: ClipData clip = clipboardManager.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { String text = clip.getItemAt(0).coerceToText(getActivity()).toString(); onCardsImported(mExportHelper.importCards(text)); } return true; case R.id.copy: clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards())); Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); return true; case R.id.share: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards()); startActivity(intent); return true; case R.id.save: exportToFile(); return true; } } catch (Exception ex) { Utils.showError(getActivity(), ex); } return false; }
From source file:com.game.simple.Game3.java
public static void openImage() { //---timer---// //StartReConnect(); //-----------// Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra("return-data", true); self.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE); }
From source file:br.com.anteros.vendas.gui.ManutencaoTabelasActivity.java
private void selecionarArquivoCompartilhar() { File importFolder = new File(Environment.getExternalStorageDirectory() + "/backup/"); final File importFiles[] = importFolder.listFiles(); if (importFiles == null || importFiles.length == 0) { Toast.makeText(this, "Pasta de backup vazia", Toast.LENGTH_SHORT).show(); return;//from ww w . java2 s . co m } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Selecionar arquivo:"); builder.setSingleChoiceItems(importFolder.list(), 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { File importDatabaseFile = importFiles[whichButton]; Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("*/*"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "File Name"); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(importDatabaseFile)); startActivity(Intent.createChooser(emailIntent, "Share File")); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.calgen.udacity.lego.ui.ArticleDetailFragment.java
@OnClick(R.id.share_fab) public void onClick() { startActivity(Intent.createChooser(ShareCompat.IntentBuilder.from(getActivity()).setType("text/plain") .setText("Some sample text").getIntent(), getString(R.string.action_share))); }
From source file:com.duy.pascal.ui.editor.EditorDelegate.java
private void selectMediaUrl() { Intent i = new Intent(); i.setType("audio/*"); i.setAction(Intent.ACTION_GET_CONTENT); Intent intent = Intent.createChooser(i, "Complete action using"); mActivity.startActivityForResult(intent, EditorActivity.ACTION_PICK_MEDIA_URL); }
From source file:com.auto.venerisauto.aftersales.services.various.KteoActivity.java
private void sendEmail() { // info@venerisauto.gr new Intent(Intent.ACTION_VIEW); Uri data = // Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + // "blah blah body" + "&to=" + "sendme@me.com"); Intent myIntent = getIntent();/* w ww .ja v a 2 s. com*/ String[] recipients = { "info@venerisauto.gr" }; Intent email = new Intent(Intent.ACTION_VIEW); recipients[0] = email_recipient; // prompts email clients only email.setType("message/rfc822"); name = (EditText) findViewById(R.id.EditTextName1); emailText = (EditText) findViewById(R.id.EditTextName3); phone = (EditText) findViewById(R.id.EditTextName2); carModel = (EditText) findViewById(R.id.EditTextName4); carNumber = (EditText) findViewById(R.id.EditTextName5); date = (TextView) findViewById(R.id.selectedDate); carVendor = (EditText) findViewById(R.id.car_vendor); licenseDate = (TextView) findViewById(R.id.date_licence_text); lastCheckDate = (TextView) findViewById(R.id.last_date_text); comments = (EditText) findViewById(R.id.EditTextComments); String subject = new StringBuilder().append(" ") .append(" ?? ").append(" ") .append(myIntent.getStringExtra("carVendor")).toString(); String body = new StringBuilder().append(": ").append(name.getText().toString()) .append("\n : ").append(phone.getText().toString()).append("\n E-mail: ") .append(emailText.getText().toString()).append("\n ? : ") .append(carVendor.getText().toString()).append("\n : ") .append(carModel.getText().toString()).append("\n ? 1 : ") .append(licenseDate.getText().toString()).append("\n ? ?: ") .append(carNumber.getText().toString()) .append("\n ? : ") .append(lastCheckDate.getText().toString()) .append("\n ? KTEO: ").append(date.getText().toString()) .append("\n : ").append(comments.getText().toString()).toString(); Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body + "&to=" + recipients[0]); email.setData(data); try { // the user can choose the email client startActivity(Intent.createChooser(email, "Choose an email client from...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(KteoActivity.this, "No email client installed.", Toast.LENGTH_LONG).show(); } }
From source file:fr.bmartel.android.iotf.app.BaseActivity.java
/** * process menu item selected/*ww w .j av a 2 s .c om*/ * * @param menuItem * @param mDrawer * @param context */ protected void selectDrawerItem(MenuItem menuItem, DrawerLayout mDrawer, Context context) { switch (menuItem.getItemId()) { case R.id.report_bugs: { Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "kiruazoldik92@gmail.com", null)); intent.putExtra(Intent.EXTRA_SUBJECT, "iotf Issue"); intent.putExtra(Intent.EXTRA_TEXT, "Your error report here..."); context.startActivity(Intent.createChooser(intent, "Report a problem")); break; } case R.id.open_source_components: { OpenSourceItemsDialog d = new OpenSourceItemsDialog(); android.support.v4.app.FragmentManager manager = getSupportFragmentManager(); d.show(manager, "open_source_components"); break; } case R.id.about_app: { AboutDialog dialog = new AboutDialog(context); dialog.show(); break; } } mDrawer.closeDrawers(); }
From source file:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.image_menu, menu); MenuItem shareItem = menu.findItem(R.id.menu_share); shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override/* w w w. j a v a 2 s.com*/ public boolean onMenuItemClick(MenuItem item) { try { ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AnalyticsHelper.getInstance().sendImageShareEvent(img.getUrl()); Uri bmpUri; if (img.isLocal()) { bmpUri = Uri.parse("content://" + AssetProvider.CONTENT_URI + "/" + img.getUrl()); } else { ImageView iv = (ImageView) findViewById(R.id.picImageView); bmpUri = getLocalBitmapUri(iv); } if (bmpUri != null) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_item))); AnalyticsHelper.getInstance().sendImageShareCompleted(); return true; } else { AnalyticsHelper.getInstance().sendImageShareCanceled(); return false; } } catch (Exception e) { AnalyticsHelper.getInstance().sendImageShareFailed(e.getMessage()); return false; } } }); MenuItem downloadItem = menu.findItem(R.id.download_asset); downloadItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Context context = ImageDetailActivity.this; String appDirectoryName = context.getString(R.string.app_name); File imageRoot = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AssetManager assetManager = context.getAssets(); try { InputStream is = assetManager.open(img.getUrl()); String fileName = img.getUrl().split("/")[1]; imageRoot.mkdirs(); File image = new File(imageRoot, fileName); byte[] buffer = new byte[BUFFER_LENGHT]; FileOutputStream fos = new FileOutputStream(image); int read = 0; while ((read = is.read(buffer, 0, 1024)) >= 0) { fos.write(buffer, 0, read); } fos.flush(); fos.close(); is.close(); String[] paths = { image.getAbsolutePath() }; MediaScannerConnection.scanFile(context, paths, null, null); NotificationHelper.showNotification(context, context.getString(R.string.download_image_succesfull)); AnalyticsHelper.getInstance().sendDownloadImage(fileName); } catch (Exception e) { NotificationHelper.showNotification(context, context.getString(R.string.download_no_permissions)); AnalyticsHelper.getInstance().sendImageDownloadFailed(e.getMessage()); } return true; } }); return true; }