List of usage examples for android.content Intent ACTION_SEND
String ACTION_SEND
To view the source code for android.content Intent ACTION_SEND.
Click Source Link
From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java
private void generateAndSendGeoJsonToolReport() { FiskInfoUtility fiskInfoUtility = new FiskInfoUtility(); JSONObject featureCollection = new JSONObject(); try {/*from www .j a v a2s . c om*/ Set<Map.Entry<String, ArrayList<ToolEntry>>> tools = user.getToolLog().myLog.entrySet(); JSONArray featureList = new JSONArray(); for (final Map.Entry<String, ArrayList<ToolEntry>> dateEntry : tools) { for (final ToolEntry toolEntry : dateEntry.getValue()) { if (toolEntry.getToolStatus() == ToolEntryStatus.STATUS_RECEIVED || toolEntry.getToolStatus() == ToolEntryStatus.STATUS_REMOVED) { continue; } toolEntry.setToolStatus(toolEntry.getToolStatus() == ToolEntryStatus.STATUS_REMOVED_UNCONFIRMED ? ToolEntryStatus.STATUS_REMOVED_UNCONFIRMED : ToolEntryStatus.STATUS_SENT_UNCONFIRMED); JSONObject gjsonTool = toolEntry.toGeoJson(mGpsLocationTracker); featureList.put(gjsonTool); } } if (featureList.length() == 0) { Toast.makeText(getActivity(), getString(R.string.no_changes_to_report), Toast.LENGTH_LONG).show(); return; } user.writeToSharedPref(getActivity()); featureCollection.put("features", featureList); featureCollection.put("type", "FeatureCollection"); featureCollection.put("crs", JSONObject.NULL); featureCollection.put("bbox", JSONObject.NULL); String toolString = featureCollection.toString(4); if (fiskInfoUtility.isExternalStorageWritable()) { fiskInfoUtility.writeMapLayerToExternalStorage(getActivity(), toolString.getBytes(), getString(R.string.tool_report_file_name), getString(R.string.format_geojson), null, false); String directoryPath = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(); String fileName = directoryPath + "/FiskInfo/api_setting.json"; File apiSettingsFile = new File(fileName); String recipient = null; if (apiSettingsFile.exists()) { InputStream inputStream; InputStreamReader streamReader; JsonReader jsonReader; try { inputStream = new BufferedInputStream(new FileInputStream(apiSettingsFile)); streamReader = new InputStreamReader(inputStream, "UTF-8"); jsonReader = new JsonReader(streamReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("email")) { recipient = jsonReader.nextString(); } else { jsonReader.skipValue(); } } jsonReader.endObject(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } } recipient = recipient == null ? getString(R.string.tool_report_recipient_email) : recipient; String[] recipients = new String[] { recipient }; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/plain"); String toolIds; StringBuilder sb = new StringBuilder(); sb.append("Redskapskoder:\n"); for (int i = 0; i < featureList.length(); i++) { sb.append(Integer.toString(i + 1)); sb.append(": "); sb.append(featureList.getJSONObject(i).getJSONObject("properties").getString("ToolId")); sb.append("\n"); } toolIds = sb.toString(); intent.putExtra(Intent.EXTRA_EMAIL, recipients); intent.putExtra(Intent.EXTRA_TEXT, toolIds); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.tool_report_email_header)); File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/FiskInfo/Redskapsrapport.geojson"); Uri uri = Uri.fromFile(file); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(intent, getString(R.string.send_tool_report_intent_header))); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.androzic.MapActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.menuSearch: onSearchRequested();/*from w w w.j a v a2 s . c o m*/ return true; case R.id.menuAddWaypoint: { double[] loc = application.getMapCenter(); Waypoint waypoint = new Waypoint("", "", loc[0], loc[1]); waypoint.date = Calendar.getInstance().getTime(); int wpt = application.addWaypoint(waypoint); waypoint.name = "WPT" + wpt; application.saveDefaultWaypoints(); map.update(); return true; } case R.id.menuNewWaypoint: startActivityForResult(new Intent(this, WaypointProperties.class).putExtra("INDEX", -1), RESULT_SAVE_WAYPOINT); return true; case R.id.menuProjectWaypoint: startActivityForResult(new Intent(this, WaypointProject.class), RESULT_SAVE_WAYPOINT); return true; case R.id.menuManageWaypoints: startActivityForResult(new Intent(this, WaypointList.class), RESULT_MANAGE_WAYPOINTS); return true; case R.id.menuLoadWaypoints: startActivityForResult(new Intent(this, WaypointFileList.class), RESULT_LOAD_WAYPOINTS); return true; case R.id.menuManageTracks: startActivityForResult(new Intent(this, TrackList.class), RESULT_MANAGE_TRACKS); return true; case R.id.menuExportCurrentTrack: FragmentManager fm = getSupportFragmentManager(); TrackExportDialog trackExportDialog = new TrackExportDialog(locationService); trackExportDialog.show(fm, "track_export"); return true; case R.id.menuExpandCurrentTrack: new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.warning) .setMessage(R.string.msg_expandcurrenttrack) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (application.currentTrackOverlay != null) { Track track = locationService.getTrack(); track.show = true; application.currentTrackOverlay.setTrack(track); } } }).setNegativeButton(R.string.no, null).show(); return true; case R.id.menuClearCurrentTrack: new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.warning) .setMessage(R.string.msg_clearcurrenttrack) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (application.currentTrackOverlay != null) application.currentTrackOverlay.clear(); locationService.clearTrack(); } }).setNegativeButton(R.string.no, null).show(); return true; case R.id.menuManageRoutes: startActivityForResult(new Intent(this, RouteList.class).putExtra("MODE", RouteList.MODE_MANAGE), RESULT_MANAGE_ROUTES); return true; case R.id.menuStartNavigation: if (application.getRoutes().size() > 1) { startActivity(new Intent(this, RouteList.class).putExtra("MODE", RouteList.MODE_START)); } else { startActivity(new Intent(this, RouteStart.class).putExtra("INDEX", 0)); } return true; case R.id.menuNavigationDetails: startActivity(new Intent(this, RouteDetails.class) .putExtra("index", application.getRouteIndex(navigationService.navRoute)) .putExtra("nav", true)); return true; case R.id.menuNextNavPoint: navigationService.nextRouteWaypoint(); return true; case R.id.menuPrevNavPoint: navigationService.prevRouteWaypoint(); return true; case R.id.menuStopNavigation: { navigationService.stopNavigation(); return true; } case R.id.menuHSI: startActivity(new Intent(this, HSIActivity.class)); return true; case R.id.menuInformation: startActivity(new Intent(this, Information.class)); return true; case R.id.menuMapInfo: startActivity(new Intent(this, MapInformation.class)); return true; case R.id.menuCursorMaps: startActivityForResult(new Intent(this, MapList.class).putExtra("pos", true), RESULT_LOAD_MAP_ATPOSITION); return true; case R.id.menuAllMaps: startActivityForResult(new Intent(this, MapList.class), RESULT_LOAD_MAP); return true; case R.id.menuShare: Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, R.string.currentloc); double[] sloc = application.getMapCenter(); String spos = StringFormatter.coordinates(application.coordinateFormat, " ", sloc[0], sloc[1]); i.putExtra(Intent.EXTRA_TEXT, spos); startActivity(Intent.createChooser(i, getString(R.string.menu_share))); return true; case R.id.menuCopyLocation: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); double[] cloc = application.getMapCenter(); String cpos = StringFormatter.coordinates(application.coordinateFormat, " ", cloc[0], cloc[1]); clipboard.setText(cpos); return true; } case R.id.menuPasteLocation: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { String q = clipboard.getText().toString(); try { double c[] = CoordinateParser.parse(q); if (!Double.isNaN(c[0]) && !Double.isNaN(c[1])) { boolean mapChanged = application.setMapCenter(c[0], c[1], true, false); if (mapChanged) map.updateMapInfo(); map.update(); map.setFollowing(false); } } catch (IllegalArgumentException e) { } } return true; } case R.id.menuSetAnchor: if (showDistance > 0) { application.distanceOverlay.setAncor(application.getMapCenter()); application.distanceOverlay.setEnabled(true); } return true; case R.id.menuPreferences: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { startActivity(new Intent(this, Preferences.class)); } else { startActivity(new Intent(this, PreferencesHC.class)); } return true; } return false; }
From source file:com.ichi2.anki.DeckPicker.java
public void emailFile(String path) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_SUBJECT, "AnkiDroid Apkg"); File attachment = new File(path); if (attachment.exists()) { Uri uri = Uri.fromFile(attachment); intent.putExtra(Intent.EXTRA_STREAM, uri); }/* w ww .j a v a 2 s .c o m*/ try { startActivityWithoutAnimation(intent); } catch (ActivityNotFoundException e) { Themes.showThemedToast(this, getResources().getString(R.string.no_email_client), false); } }
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 {/*w ww . j a v a 2s . com*/ 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:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to create a share intent and it can be launched. * //from w w w . ja v a 2s.co m * @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);//from w w w. j a v a2s . co 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("[ ] "); }// w w w.j a 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: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))); }