List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:im.delight.android.baselib.Social.java
/** * Constructs an email Intent for the given message details and opens the application choooser for this Intent * * @param recipient the recipient's email address * @param subject the subject of the message * @param body the body text as a string * @param captionRes the string resource ID for the application chooser's window title * @param restrictToPackage an optional package name that the Intent may be restricted to (or null) * @param context the Context instance to start the Intent from * @throws Exception if there was an error trying to launch the email Intent */// ww w . ja va 2 s . c o m public static void sendMail(final String recipient, final String subject, final String body, final int captionRes, final String restrictToPackage, final Context context) throws Exception { final String uriString = "mailto:" + Uri.encode(recipient) + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body); 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.bringcommunications.etherpay.ReceiveActivity.java
private void do_share_guts() { Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); qr_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = null;// w ww.j av a 2s.com try { path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null); if (path == null) { //turns out there's an Android bug, where it happens when the user hasn't taken a photo on the device before (i.e. gallery is empty //and hasn't been initialized.). The workaround is to initialize the photo directory manually: File sdcard = Environment.getExternalStorageDirectory(); if (sdcard != null) { File mediaDir = new File(sdcard, "DCIM/Camera"); if (!mediaDir.exists()) mediaDir.mkdirs(); } path = MediaStore.Images.Media.insertImage(getContentResolver(), qr_bitmap, "QR Code", null); } } catch (Exception e) { } if (path == null) { String msg = getResources().getString(R.string.receive_err_no_media_access_msg); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); return; } Uri imageUri = Uri.parse(path); share.putExtra(Intent.EXTRA_STREAM, imageUri); if (show_private) share.putExtra(Intent.EXTRA_TEXT, private_key); else share.putExtra(Intent.EXTRA_TEXT, acct_addr); try { startActivity(Intent.createChooser(share, "Select")); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); } }
From source file:palamarchuk.smartlife.app.fragments.ProfileFragment.java
private void feedback() { Intent sendIntent;// w ww.j av a2 s . co m sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@smartlife.com.kz" }); sendIntent.putExtra(Intent.EXTRA_SUBJECT, ""); sendIntent.putExtra(Intent.EXTRA_TEXT, ""); sendIntent.setType("image/jpeg"); try { startActivity(Intent.createChooser(sendIntent, "Send Mail")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(parentActivity, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); } }
From source file:com.doplgangr.secrecy.views.FileViewer.java
void sendMultiple(final ArrayList<FilesListFragment.DecryptArgHolder> args) { new Thread(new Runnable() { @Override/* ww w .j a v a 2s . com*/ public void run() { ArrayList<Uri> uris = new ArrayList<Uri>(); Set<String> mimes = new HashSet<String>(); MimeTypeMap myMime = MimeTypeMap.getSingleton(); for (FilesListFragment.DecryptArgHolder arg : args) { File tempFile = getFile(arg.encryptedFile, arg.onFinish); //File specified is not invalid if (tempFile != null) { if (tempFile.getParentFile().equals(Storage.getTempFolder())) tempFile = new java.io.File(Storage.getTempFolder(), tempFile.getName()); uris.add(OurFileProvider.getUriForFile(context, OurFileProvider.FILE_PROVIDER_AUTHORITY, tempFile)); mimes.add(myMime.getMimeTypeFromExtension(arg.encryptedFile.getType())); } } if (uris.size() == 0 || mimes.size() == 0) return; Intent newIntent; if (uris.size() == 1) { newIntent = new Intent(Intent.ACTION_SEND); newIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0)); } else { newIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); newIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } if (mimes.size() > 1) newIntent.setType("text/plain"); //Mixed filetypes else newIntent.setType(new ArrayList<String>(mimes).get(0)); newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent chooserIntent = generateCustomChooserIntent(newIntent, uris); try { startActivity(Intent.createChooser(chooserIntent, CustomApp.context.getString(R.string.Dialog__send_file))); FilesActivity.onPauseDecision.startActivity(); } catch (android.content.ActivityNotFoundException e) { Util.toast(context, CustomApp.context.getString(R.string.Error__no_activity_view), Toast.LENGTH_LONG); FilesActivity.onPauseDecision.finishActivity(); } } }).start(); }
From source file:ca.psiphon.ploggy.FragmentComposeMessage.java
private void selectPicture() { Intent intent;// w w w . java 2 s .c om if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); } else { // TODO: properly support the new Storage Access Framework invoked for // Intent.ACTION_GET_CONTENT on KitKat: // https://developer.android.com/guide/topics/providers/document-provider.html // This includes getting results from cloud providers such as // Drive -- which are only available as streams, not files. // For now, forcing the equivilent of pre-KitKat gallery selection... intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } intent.setType("image/*"); // Note: assumes nested fragment getParentFragment().startActivityForResult( Intent.createChooser(intent, getText(R.string.prompt_compose_message_select_picture)), REQUEST_CODE_SELECT_IMAGE); }
From source file:com.dnielfe.manager.AppManager.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; String packagename = mAppList.get(index).packageName; switch (item.getItemId()) { case ID_LAUNCH: Intent i = pm.getLaunchIntentForPackage(packagename); startActivity(i);/*from w ww. j a v a2s.c o m*/ break; case ID_MANAGE: startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + packagename))); break; case ID_UNINSTALL: Intent i1 = new Intent(Intent.ACTION_DELETE); i1.setData(Uri.parse("package:" + packagename)); startActivity(i1); get_downloaded_apps(); break; case ID_MARKET: Intent intent1 = new Intent(Intent.ACTION_VIEW); intent1.setData(Uri.parse("market://details?id=" + packagename)); startActivity(intent1); break; case ID_SEND: try { ApplicationInfo info1 = pm.getApplicationInfo(packagename, 0); String source_dir = info1.sourceDir; File file = new File(source_dir); Uri uri11 = Uri.fromFile(file.getAbsoluteFile()); Intent infointent = new Intent(Intent.ACTION_SEND); infointent.setType("application/zip"); infointent.putExtra(Intent.EXTRA_STREAM, uri11); startActivity(Intent.createChooser(infointent, getString(R.string.share))); } catch (Exception e) { Toast.makeText(AppManager.this, "Error", Toast.LENGTH_SHORT).show(); } break; } return false; }
From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java
private void send() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); Intent originalIntent = getIntent(); if (Intent.ACTION_SEND.equals(originalIntent.getAction())) { // Copy extras from the original intent because they might contain // additional information about the URL (e.g., the title of a // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid // overwriting the TinyURL. intent.putExtras(originalIntent.getExtras()); }/*from ww w . j a v a2 s .com*/ intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl); try { CharSequence template = getText(R.string.title_send); String title = String.format(String.valueOf(template), mTinyUrl); startActivity(Intent.createChooser(intent, title)); finish(); } catch (ActivityNotFoundException e) { handleError(e); } }
From source file:ch.fixme.status.Main.java
@Override public void startActivity(Intent intent) { // http://stackoverflow.com/questions/13691241/autolink-not-working-on-htc-htclinkifydispatcher try {//from ww w . j av a 2 s .c o m /* First attempt at fixing an HTC broken by evil Apple patents. */ if (intent.getComponent() != null && ".HtcLinkifyDispatcherActivity".equals(intent.getComponent().getShortClassName())) intent.setComponent(null); super.startActivity(intent); } catch (ActivityNotFoundException e) { /* * Probably an HTC broken by evil Apple patents. This is not * perfect, but better than crashing the whole application. */ super.startActivity(Intent.createChooser(intent, null)); } }