List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:com.aujur.ebookreader.activity.ReadingFragment.java
public void share(int from, int to, String selectedText) { int pageStart = bookView.getStartOfCurrentPage(); String text = bookTitle + ", " + authorField.getText() + "\n"; int offset = pageStart + from; int pageNumber = bookView.getPageNumberFor(bookView.getIndex(), offset); int totalPages = bookView.getTotalNumberOfPages(); int percentage = bookView.getPercentageFor(bookView.getIndex(), offset); if (pageNumber != -1) { text = text + String.format(getString(R.string.page_number_of), pageNumber, totalPages) + " (" + progressPercentage + "%)\n\n"; } else {/*from w ww . j a v a 2s . c o m*/ text += "" + progressPercentage + "%\n\n"; } text += selectedText; Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, text); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getText(R.string.abs__shareactionprovider_share_with))); }
From source file:org.cryptsecure.Utility.java
/** * Select attachment.// ww w .ja v a 2 s . co m * * @param activity * the activity */ public static void selectFromGallery(Activity activity) { Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 19) { intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"), Utility.SELECT_PICTURE); } else { intent.setType("image/*"); intent.setAction(Intent.ACTION_PICK); activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"), Utility.SELECT_PICTURE); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to create a share intent and it can be launched. * //from w ww. j a v a 2 s . c om * @param context * @param type Mime type. * @param nameApp You can filter the application you want to share with. Use "wha", "twitt", etc. * @param title The title of the share.Take in account that sometimes is not possible to add the title. * @param data The data, can be a file or a text. * @param isBinaryData If the share has a data file, set to TRUE otherwise FALSE. */ @SuppressLint("DefaultLocale") public static Intent share_newSharingIntent(Context context, String type, String nameApp, String title, String data, boolean isBinaryData, boolean launch) { Intent res = null; Intent share = new Intent(Intent.ACTION_SEND); share.setType(type); List<Intent> targetedShareIntents = new ArrayList<Intent>(); List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Intent targetedShare = new Intent(Intent.ACTION_SEND); targetedShare.setType(type); if (title != null) { targetedShare.putExtra(Intent.EXTRA_SUBJECT, title); targetedShare.putExtra(Intent.EXTRA_TITLE, title); if (data != null && !isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, data); } } if (data != null && isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, title); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(data))); } if (nameApp != null) { if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } else { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); res = chooserIntent; if (launch) { context.startActivity(chooserIntent); } } return res; }
From source file:com.androzic.MapActivity.java
@Override public void onWaypointShare(final Waypoint waypoint) { Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, R.string.currentloc); String coords = StringFormatter.coordinates(application.coordinateFormat, " ", waypoint.latitude, waypoint.longitude);// w w w .j a v a2s . c o m i.putExtra(Intent.EXTRA_TEXT, waypoint.name + " @ " + coords); startActivity(Intent.createChooser(i, getString(R.string.menu_share))); }
From source file:org.openintents.shopping.ui.ShoppingActivity.java
private void sendList() { if (mItemsView.getAdapter() instanceof CursorAdapter) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < mItemsView.getAdapter().getCount(); i++) { Cursor item = (Cursor) mItemsView.getAdapter().getItem(i); if (item.getLong(mStringItemsSTATUS) == ShoppingContract.Status.BOUGHT) { sb.append("[X] "); } else { sb.append("[ ] "); }/*from w w w .ja v a 2 s. c o m*/ String quantity = item.getString(mStringItemsQUANTITY); long pricecent = item.getLong(mStringItemsITEMPRICE); String price = PriceConverter.getStringFromCentPrice(pricecent); String tags = item.getString(mStringItemsITEMTAGS); if (!TextUtils.isEmpty(quantity)) { sb.append(quantity); sb.append(" "); } String units = item.getString(mStringItemsITEMUNITS); if (!TextUtils.isEmpty(units)) { sb.append(units); sb.append(" "); } sb.append(item.getString(mStringItemsITEMNAME)); // Put additional info (price, tags) in brackets boolean p = !TextUtils.isEmpty(price); boolean t = !TextUtils.isEmpty(tags); if (p || t) { sb.append(" ("); if (p) { sb.append(price); } if (p && t) { sb.append(", "); } if (t) { sb.append(tags); } sb.append(")"); } sb.append("\n"); } Intent i = new Intent(); i.setAction(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, getCurrentListName()); i.putExtra(Intent.EXTRA_TEXT, sb.toString()); try { startActivity(Intent.createChooser(i, getString(R.string.send))); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.email_not_available, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Email client not installed"); } } else { Toast.makeText(this, R.string.empty_list_not_sent, Toast.LENGTH_SHORT); } }
From source file:org.thoughtland.xlocation.ActivityShare.java
public void fileChooser() { Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT); Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/.xlocation/"); chooseFile.setDataAndType(uri, "text/xml"); Intent intent = Intent.createChooser(chooseFile, getString(R.string.app_name)); startActivityForResult(intent, ACTIVITY_IMPORT_SELECT); }
From source file:edu.mit.viral.shen.DroidFish.java
private final void shareGame() { Intent i = new Intent(Intent.ACTION_SEND); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, ctrl.getPGN()); startActivity(Intent.createChooser(i, getString(R.string.share_pgn_game))); }
From source file:com.if3games.chessonline.DroidFish.java
private final void shareGame() { Intent i = new Intent(Intent.ACTION_SEND); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); i.setType("text/plain"); //i.putExtra(Intent.EXTRA_TEXT, ctrl.getPGN()); i.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_name) + " " + ConstantsData.MARKET_URL_HTTP); startActivity(Intent.createChooser(i, getString(R.string.share_pgn_game))); }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
private void shareContact() { final String lookupKey = mContactData.getLookupKey(); final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(Contacts.CONTENT_VCARD_TYPE); intent.putExtra(Intent.EXTRA_STREAM, shareUri); // Launch chooser to share contact via final CharSequence chooseTitle = getText(R.string.share_via); final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); try {/*from ww w . j a va 2 s . c o m*/ mHasIntentLaunched = true; ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); } catch (final ActivityNotFoundException ex) { Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); } }
From source file:com.irccloud.android.activity.MainActivity.java
private void insertPhoto() { if (buffer == null) return;/* w w w.jav a 2 s .c o m*/ AlertDialog.Builder builder; AlertDialog dialog; builder = new AlertDialog.Builder(this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); String[] items = (Build.VERSION.SDK_INT < 19 || !NetworkConnection.getInstance().uploadsAvailable()) ? new String[] { "Take a Photo", "Choose Existing", "Start a Pastebin", "Pastebins" } : new String[] { "Take a Photo", "Choose Existing Photo", "Choose Existing Document", "Start a Pastebin", "Pastebins" }; if (NetworkConnection.getInstance().uploadsAvailable()) { items = Arrays.copyOf(items, items.length + 1); items[items.length - 1] = "File Uploads"; } final String[] dialogItems = items; builder.setItems(dialogItems, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent i; if (buffer != null) { switch (dialogItems[which]) { case "Take a Photo": try { File imageDir = new File(Environment.getExternalStorageDirectory(), "IRCCloud"); imageDir.mkdirs(); new File(imageDir, ".nomedia").createNewFile(); imageCaptureURI = Uri .fromFile(File.createTempFile("irccloudcapture", ".jpg", imageDir)); i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureURI); startActivityForResult(i, REQUEST_CAMERA); } catch (IOException e) { } break; case "Choose Existing": case "Choose Existing Photo": i = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "Select Picture"), REQUEST_PHOTO); break; case "Choose Existing Document": i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "Select A Document"), REQUEST_DOCUMENT); break; case "Start a Pastebin": show_pastebin_prompt(); break; case "Pastebins": i = new Intent(MainActivity.this, PastebinsActivity.class); startActivity(i); break; case "File Uploads": i = new Intent(MainActivity.this, UploadsActivity.class); i.putExtra("cid", buffer.cid); i.putExtra("to", buffer.name); i.putExtra("msg", messageTxt.getText().toString()); startActivityForResult(i, REQUEST_UPLOADS); break; } } dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.show(); }