List of usage examples for android.content Intent EXTRA_TEXT
String EXTRA_TEXT
To view the source code for android.content Intent EXTRA_TEXT.
Click Source Link
From source file:com.irccloud.android.activity.MainActivity.java
private void setFromIntent(Intent intent) { launchBid = -1;//from ww w . ja v a 2 s. com launchURI = null; if (NetworkConnection.getInstance().ready) setIntent(new Intent(this, MainActivity.class)); if (intent.hasExtra("bid")) { int new_bid = intent.getIntExtra("bid", 0); if (NetworkConnection.getInstance().ready && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && BuffersDataSource.getInstance().getBuffer(new_bid) == null) { Crashlytics.log(Log.WARN, "IRCCloud", "Invalid bid requested by launch intent: " + new_bid); Notifications.getInstance().deleteNotificationsForBid(new_bid); if (excludeBIDTask != null) excludeBIDTask.cancel(true); excludeBIDTask = new ExcludeBIDTask(); excludeBIDTask.execute(new_bid); return; } else if (BuffersDataSource.getInstance().getBuffer(new_bid) != null) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Found BID, switching buffers"); if (buffer != null && buffer.bid != new_bid) backStack.add(0, buffer.bid); buffer = BuffersDataSource.getInstance().getBuffer(new_bid); server = ServersDataSource.getInstance().getServer(buffer.cid); } else { Crashlytics.log(Log.DEBUG, "IRCCloud", "BID not found, will try after reconnecting"); launchBid = new_bid; } } if (intent.getData() != null && intent.getData().getScheme() != null && intent.getData().getScheme().startsWith("irc")) { if (open_uri(intent.getData())) { return; } else { launchURI = intent.getData(); buffer = null; server = null; } } else if (intent.hasExtra("cid")) { if (buffer == null) { buffer = BuffersDataSource.getInstance().getBufferByName(intent.getIntExtra("cid", 0), intent.getStringExtra("name")); if (buffer != null) { server = ServersDataSource.getInstance().getServer(intent.getIntExtra("cid", 0)); } } } if (buffer == null) { server = null; } else { if (intent.hasExtra(Intent.EXTRA_STREAM)) { String type = getContentResolver().getType((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); if (type != null && type.startsWith("image/") && (!NetworkConnection.getInstance().uploadsAvailable() || PreferenceManager.getDefaultSharedPreferences(this) .getString("image_service", "IRCCloud").equals("imgur"))) { new ImgurRefreshTask((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)).execute((Void) null); } else { fileUploadTask = new FileUploadTask((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM), this); fileUploadTask.execute((Void) null); } } if (intent.hasExtra(Intent.EXTRA_TEXT)) { if (intent.hasExtra(Intent.EXTRA_SUBJECT)) buffer.draft = intent.getStringExtra(Intent.EXTRA_SUBJECT) + " (" + intent.getStringExtra(Intent.EXTRA_TEXT) + ")"; else buffer.draft = intent.getStringExtra(Intent.EXTRA_TEXT); } } if (buffer == null) { launchBid = intent.getIntExtra("bid", -1); } else { onBufferSelected(buffer.bid); } }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int rowId = (int) info.id; switch (item.getItemId()) { case Constants.SAVE_CONTEXT_ITEM: new SaveTask(true, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.UNSAVE_CONTEXT_ITEM: new SaveTask(false, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.HIDE_CONTEXT_ITEM: new HideTask(true, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.UNHIDE_CONTEXT_ITEM: new HideTask(false, getOpThingInfo(), mSettings, this).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, getOpThingInfo().getUrl()); try {// w w w . j av a 2 s. c o m startActivity(Intent.createChooser(intent, "Share Link")); } catch (android.content.ActivityNotFoundException ex) { } return true; case Constants.DIALOG_HIDE_COMMENT: hideComment(rowId); return true; case Constants.DIALOG_SHOW_COMMENT: showComment(rowId); return true; case Constants.DIALOG_GOTO_PARENT: int myIndent = mCommentsAdapter.getItem(rowId).getIndent(); int parentRowId; for (parentRowId = rowId - 1; parentRowId >= 0; parentRowId--) if (mCommentsAdapter.getItem(parentRowId).getIndent() < myIndent) break; getListView().setSelection(parentRowId); return true; case Constants.DIALOG_VIEW_PROFILE: Intent i = new Intent(this, ProfileActivity.class); i.setData(Util.createProfileUri(mCommentsAdapter.getItem(rowId).getAuthor())); startActivity(i); return true; case Constants.DIALOG_EDIT: mReplyTargetName = mCommentsAdapter.getItem(rowId).getName(); mEditTargetBody = mCommentsAdapter.getItem(rowId).getBody(); showDialog(Constants.DIALOG_EDIT); return true; case Constants.DIALOG_DELETE: mReplyTargetName = mCommentsAdapter.getItem(rowId).getName(); // It must be a comment, since the OP selftext is reached via options menu, not context menu mDeleteTargetKind = Constants.COMMENT_KIND; showDialog(Constants.DIALOG_DELETE); return true; case Constants.DIALOG_REPORT: mReportTargetName = mCommentsAdapter.getItem(rowId).getName(); showDialog(Constants.DIALOG_REPORT); return true; default: return super.onContextItemSelected(item); } }
From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java
private void generateAndSendGeoJsonToolReport() { FiskInfoUtility fiskInfoUtility = new FiskInfoUtility(); JSONObject featureCollection = new JSONObject(); try {/*from w ww. j a v a 2 s. co m*/ 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 ww w . j av a 2s .co 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.android.mail.compose.ComposeActivity.java
/** * Fill all the widgets with the content found in the Intent Extra, if any. * Also apply the same style to all widgets. Note: if initFromExtras is * called as a result of switching between reply, reply all, and forward per * the latest revision of Gmail, and the user has already made changes to * attachments on a previous incarnation of the message (as a reply, reply * all, or forward), the original attachments from the message will not be * re-instantiated. The user's changes will be respected. This follows the * web gmail interaction./* w w w. j av a 2 s . co m*/ * @return {@code true} if the activity should not call {@link #finishSetup}. */ public boolean initFromExtras(Intent intent) { // If we were invoked with a SENDTO intent, the value // should take precedence final Uri dataUri = intent.getData(); if (dataUri != null) { if (MAIL_TO.equals(dataUri.getScheme())) { initFromMailTo(dataUri.toString()); } else { if (!mAccount.composeIntentUri.equals(dataUri)) { String toText = dataUri.getSchemeSpecificPart(); if (toText != null) { mTo.setText(""); addToAddresses(Arrays.asList(TextUtils.split(toText, ","))); } } } } String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL); if (extraStrings != null) { addToAddresses(Arrays.asList(extraStrings)); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC); if (extraStrings != null) { addCcAddresses(Arrays.asList(extraStrings), null); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC); if (extraStrings != null) { addBccAddresses(Arrays.asList(extraStrings)); } String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (extraString != null) { mSubject.setText(extraString); } for (String extra : ALL_EXTRAS) { if (intent.hasExtra(extra)) { String value = intent.getStringExtra(extra); if (EXTRA_TO.equals(extra)) { addToAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_CC.equals(extra)) { addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null); } else if (EXTRA_BCC.equals(extra)) { addBccAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_SUBJECT.equals(extra)) { mSubject.setText(value); } else if (EXTRA_BODY.equals(extra)) { setBody(value, true /* with signature */); } else if (EXTRA_QUOTED_TEXT.equals(extra)) { initQuotedText(value, true /* shouldQuoteText */); } } } Bundle extras = intent.getExtras(); if (extras != null) { CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT); setBody((text != null) ? text : "", true /* with signature */); // TODO - support EXTRA_HTML_TEXT } mExtraValues = intent.getParcelableExtra(EXTRA_VALUES); if (mExtraValues != null) { LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString()); initExtraValues(mExtraValues); return true; } return false; }
From source file:com.if3games.chessonline.DroidFish.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case RESULT_SETTINGS: handlePrefsChange();//from w w w . ja va 2 s .co m break; case RESULT_EDITBOARD: if (resultCode == RESULT_OK) { try { String fen = data.getAction(); ctrl.setFENOrPGN(fen); setBoardFlip(false); } catch (ChessParseError e) { } } break; case RESULT_LOAD_PGN: if (resultCode == RESULT_OK) { try { String pgn = data.getAction(); int modeNr = ctrl.getGameMode().getModeNr(); if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME)) newGameMode(GameMode.EDIT_GAME); ctrl.setFENOrPGN(pgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); if (pathName != null) { Editor editor = settings.edit(); editor.putString("currentScidFile", pathName); editor.putInt("currFT", FT_SCID); editor.commit(); Intent i = new Intent(DroidFish.this, LoadScid.class); i.setAction("com.if3games.chessonline.loadScid"); i.putExtra("com.if3games.chessonline.pathname", pathName); startActivityForResult(i, RESULT_LOAD_PGN); } } break; case RESULT_OI_PGN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadPGNFromFile(pathName); } break; case RESULT_OI_PGN_SAVE: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { if ((pathName.length() > 0) && !pathName.contains(".")) pathName += ".pgn"; savePGNToFile(pathName, false); } } break; case RESULT_OI_FEN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadFENFromFile(pathName); } break; case RESULT_GET_FEN: if (resultCode == RESULT_OK) { String fen = data.getStringExtra(Intent.EXTRA_TEXT); if (fen == null) { String pathName = getFilePathFromUri(data.getData()); loadFENFromFile(pathName); } setFenHelper(fen); } break; case RESULT_LOAD_FEN: if (resultCode == RESULT_OK) { String fen = data.getAction(); setFenHelper(fen); } break; // GMS case RC_SELECT_PLAYERS: // we got the result from the "select players" UI -- ready to create the room handleSelectPlayersResult(resultCode, data, gmsGameVariantNumber); break; case RC_INVITATION_INBOX: // we got the result from the "select invitation" UI (invitation inbox). We're // ready to accept the selected invitation: handleInvitationInboxResult(resultCode, data); break; case RC_WAITING_ROOM: // we got the result from the "waiting room" UI. if (resultCode == Activity.RESULT_OK) { // ready to start playing //Log.d(TAG, "Starting game (waiting room returned OK)."); //if(!imNotFirst) //sendImFirstLevelNumberForStart(); if (gmsGameVariantNumber != -1) startGame(true, gmsGameVariantNumber); } else if (resultCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) { // player indicated that they want to leave the room leaveRoom(); } else if (resultCode == Activity.RESULT_CANCELED) { // Dialog was cancelled (user pressed back key, for instance). In our game, // this means leaving the room too. In more elaborate games, this could mean // something else (like minimizing the waiting room UI). leaveRoom(); } break; } }
From source file:edu.mit.viral.shen.DroidFish.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_SETTINGS: handlePrefsChange();/*from ww w.j a va 2s . c om*/ break; case RESULT_EDITBOARD: if (resultCode == RESULT_OK) { try { String fen = data.getAction(); startPosition = fen; ctrl.setData(fen); ctrl.setFENOrPGN(fen); mDatabase.updateStartFen(fen, game_number); ctrl.setFENOrPGN(fen); setBoardFlip(false); } catch (ChessParseError e) { } } break; case RESULT_LOAD_PGN: if (resultCode == RESULT_OK) { try { String pgn = data.getAction(); int modeNr = ctrl.getGameMode().getModeNr(); if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME)) newGameMode(GameMode.EDIT_GAME); ctrl.setFENOrPGN(pgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); if (pathName != null) { Editor editor = settings.edit(); editor.putString("currentScidFile", pathName); editor.putInt("currFT", FT_SCID); editor.commit(); Intent i = new Intent(DroidFish.this, LoadScid.class); i.setAction("edu.mit.viral.shen.loadScid"); i.putExtra("edu.mit.viral.shen.pathname", pathName); startActivityForResult(i, RESULT_LOAD_PGN); } } break; case RESULT_OI_PGN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadPGNFromFile(pathName); } break; case RESULT_OI_PGN_SAVE: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { if ((pathName.length() > 0) && !pathName.contains(".")) pathName += ".pgn"; savePGNToFile(pathName, false); } } break; case RESULT_OI_FEN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadFENFromFile(pathName); } break; case RESULT_GET_FEN: if (resultCode == RESULT_OK) { String fen = data.getStringExtra(Intent.EXTRA_TEXT); if (fen == null) { String pathName = getFilePathFromUri(data.getData()); loadFENFromFile(pathName); } setFenHelper(fen); } break; case RESULT_LOAD_FEN: if (resultCode == RESULT_OK) { String fen = data.getAction(); setFenHelper(fen); } break; } }
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 w w.ja va 2 s. 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:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to create a share intent and it can be launched. * /*from www. jav a2s .com*/ * @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; }