List of usage examples for android.content Intent ACTION_SEND_MULTIPLE
String ACTION_SEND_MULTIPLE
To view the source code for android.content Intent ACTION_SEND_MULTIPLE.
Click Source Link
From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java
private Intent createSendIntent() { Intent sendIntent;//from w w w . j a v a 2s . co m // file if (mOutputUris.size() == 1) { sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris.get(0)); } else { sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris); } sendIntent.setType(Constants.MIME_TYPE_ENCRYPTED_ALTERNATE); EncryptActivity modeInterface = (EncryptActivity) getActivity(); EncryptModeFragment modeFragment = modeInterface.getModeFragment(); if (!modeFragment.isAsymmetric()) { return sendIntent; } String[] encryptionUserIds = modeFragment.getAsymmetricEncryptionUserIds(); if (encryptionUserIds == null) { return sendIntent; } Set<String> users = new HashSet<>(); for (String user : encryptionUserIds) { OpenPgpUtils.UserId userId = KeyRing.splitUserId(user); if (userId.email != null) { users.add(userId.email); } } // pass trough email addresses as extra for email applications sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()])); return sendIntent; }
From source file:com.keylesspalace.tusky.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT); if (theme.equals("black")) { setTheme(R.style.TuskyDialogActivityBlackTheme); }//from w w w .j a v a2 s. com setContentView(R.layout.activity_compose); replyTextView = findViewById(R.id.composeReplyView); replyContentTextView = findViewById(R.id.composeReplyContentView); textEditor = findViewById(R.id.composeEditField); mediaPreviewBar = findViewById(R.id.compose_media_preview_bar); contentWarningBar = findViewById(R.id.composeContentWarningBar); contentWarningEditor = findViewById(R.id.composeContentWarningField); charactersLeft = findViewById(R.id.composeCharactersLeftView); tootButton = findViewById(R.id.composeTootButton); pickButton = findViewById(R.id.composeAddMediaButton); visibilityButton = findViewById(R.id.composeToggleVisibilityButton); contentWarningButton = findViewById(R.id.composeContentWarningButton); emojiButton = findViewById(R.id.composeEmojiButton); hideMediaToggle = findViewById(R.id.composeHideMediaButton); emojiView = findViewById(R.id.emojiView); emojiList = Collections.emptyList(); saveTootHelper = new SaveTootHelper(database.tootDao(), this); // Setup the toolbar. Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // setup the account image final AccountEntity activeAccount = accountManager.getActiveAccount(); if (activeAccount != null) { ImageView composeAvatar = findViewById(R.id.composeAvatar); if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) { composeAvatar.setImageResource(R.drawable.avatar_default); } else { Picasso.with(this).load(activeAccount.getProfilePictureUrl()).error(R.drawable.avatar_default) .placeholder(R.drawable.avatar_default).into(composeAvatar); } composeAvatar.setContentDescription( getString(R.string.compose_active_account_description, activeAccount.getFullName())); mastodonApi.getInstance().enqueue(new Callback<Instance>() { @Override public void onResponse(@NonNull Call<Instance> call, @NonNull Response<Instance> response) { if (response.isSuccessful() && response.body().getMaxTootChars() != null) { maximumTootCharacters = response.body().getMaxTootChars(); updateVisibleCharactersLeft(); cacheInstanceMetadata(activeAccount); } } @Override public void onFailure(@NonNull Call<Instance> call, @NonNull Throwable t) { Log.w(TAG, "error loading instance data", t); loadCachedInstanceMetadata(activeAccount); } }); mastodonApi.getCustomEmojis().enqueue(new Callback<List<Emoji>>() { @Override public void onResponse(@NonNull Call<List<Emoji>> call, @NonNull Response<List<Emoji>> response) { emojiList = response.body(); setEmojiList(emojiList); cacheInstanceMetadata(activeAccount); } @Override public void onFailure(@NonNull Call<List<Emoji>> call, @NonNull Throwable t) { Log.w(TAG, "error loading custom emojis", t); loadCachedInstanceMetadata(activeAccount); } }); } else { // do not do anything when not logged in, activity will be finished in super.onCreate() anyway return; } composeOptionsView = findViewById(R.id.composeOptionsBottomSheet); composeOptionsView.setListener(this); composeOptionsBehavior = BottomSheetBehavior.from(composeOptionsView); composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); addMediaBehavior = BottomSheetBehavior.from(findViewById(R.id.addMediaBottomSheet)); emojiBehavior = BottomSheetBehavior.from(emojiView); emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false)); enableButton(emojiButton, false, false); // Setup the interface buttons. tootButton.setOnClickListener(v -> onSendClicked()); pickButton.setOnClickListener(v -> openPickDialog()); visibilityButton.setOnClickListener(v -> showComposeOptions()); contentWarningButton.setOnClickListener(v -> onContentWarningChanged()); emojiButton.setOnClickListener(v -> showEmojis()); hideMediaToggle.setOnClickListener(v -> toggleHideMedia()); TextView actionPhotoTake = findViewById(R.id.action_photo_take); TextView actionPhotoPick = findViewById(R.id.action_photo_pick); int textColor = ThemeUtils.getColor(this, android.R.attr.textColorTertiary); Drawable cameraIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).color(textColor) .sizeDp(18); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoTake, cameraIcon, null, null, null); Drawable imageIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).color(textColor).sizeDp(18); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoPick, imageIcon, null, null, null); actionPhotoTake.setOnClickListener(v -> initiateCameraApp()); actionPhotoPick.setOnClickListener(v -> onMediaPick()); thumbnailViewSize = getResources().getDimensionPixelSize(R.dimen.compose_media_preview_size); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ Status.Visibility startingVisibility = Status.Visibility.UNKNOWN; boolean startingHideText; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { startingVisibility = Status.Visibility .byNum(savedInstanceState.getInt("statusVisibility", Status.Visibility.PUBLIC.getNum())); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } photoUploadUri = savedInstanceState.getParcelable("photoUploadUri"); } else { statusMarkSensitive = false; startingHideText = false; photoUploadUri = null; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; ArrayList<String> loadedDraftMediaUris = null; inReplyToId = null; if (intent != null) { if (startingVisibility == Status.Visibility.UNKNOWN) { Status.Visibility preferredVisibility = Status.Visibility.byString( preferences.getString("defaultPostPrivacy", Status.Visibility.PUBLIC.serverString())); Status.Visibility replyVisibility = Status.Visibility .byNum(intent.getIntExtra(REPLY_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum())); startingVisibility = Status.Visibility .byNum(Math.max(preferredVisibility.getNum(), replyVisibility.getNum())); } inReplyToId = intent.getStringExtra(IN_REPLY_TO_ID_EXTRA); mentionedUsernames = intent.getStringArrayExtra(MENTIONED_USERNAMES_EXTRA); String contentWarning = intent.getStringExtra(CONTENT_WARNING_EXTRA); if (contentWarning != null) { startingHideText = !contentWarning.isEmpty(); if (startingHideText) { startingContentWarning = contentWarning; } } // If come from SavedTootActivity String savedTootText = intent.getStringExtra(SAVED_TOOT_TEXT_EXTRA); if (!TextUtils.isEmpty(savedTootText)) { startingText = savedTootText; textEditor.setText(savedTootText); } String savedJsonUrls = intent.getStringExtra(SAVED_JSON_URLS_EXTRA); if (!TextUtils.isEmpty(savedJsonUrls)) { // try to redo a list of media loadedDraftMediaUris = new Gson().fromJson(savedJsonUrls, new TypeToken<ArrayList<String>>() { }.getType()); } int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0); if (savedTootUid != 0) { this.savedTootUid = savedTootUid; } if (intent.hasExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA)) { replyTextView.setVisibility(View.VISIBLE); String username = intent.getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA); replyTextView.setText(getString(R.string.replying_to, username)); Drawable arrowDownIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_down) .sizeDp(12); ThemeUtils.setDrawableTint(this, arrowDownIcon, android.R.attr.textColorTertiary); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null); replyTextView.setOnClickListener(v -> { TransitionManager.beginDelayedTransition((ViewGroup) replyContentTextView.getParent()); if (replyContentTextView.getVisibility() != View.VISIBLE) { replyContentTextView.setVisibility(View.VISIBLE); Drawable arrowUpIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_up) .sizeDp(12); ThemeUtils.setDrawableTint(this, arrowUpIcon, android.R.attr.textColorTertiary); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowUpIcon, null); } else { replyContentTextView.setVisibility(View.GONE); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null); } }); } if (intent.hasExtra(REPLYING_STATUS_CONTENT_EXTRA)) { replyContentTextView.setText(intent.getStringExtra(REPLYING_STATUS_CONTENT_EXTRA)); } } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); updateHideMediaToggle(); updateVisibleCharactersLeft(); // Setup the main text field. textEditor.setOnCommitContentListener(this); final int mentionColour = textEditor.getLinkTextColors().getDefaultColor(); SpanUtilsKt.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtilsKt.highlightSpans(editable, mentionColour); updateVisibleCharactersLeft(); } }); textEditor.setAdapter(new MentionAutoCompleteAdapter(this, R.layout.item_autocomplete, this)); textEditor.setTokenizer(new MentionTokenizer()); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } startingText = builder.toString(); textEditor.setText(startingText); textEditor.setSelection(textEditor.length()); } // work around Android platform bug -> https://issuetracker.google.com/issues/67102093 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O || Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) { textEditor.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. waitForMediaLatch = new CountUpDownLatch(); // These can only be added after everything affected by the media queue is initialized. if (!ListUtils.isEmpty(loadedDraftMediaUris)) { for (String uriString : loadedDraftMediaUris) { Uri uri = Uri.parse(uriString); long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { Bitmap preview = MediaUtils.getImageThumbnail(getContentResolver(), item.uri, thumbnailViewSize); addMediaToQueue(item.id, item.type, preview, item.uri, item.mediaSize, item.readyStage, item.description); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); if (intent.getAction() != null) { switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } } for (Uri uri : uriList) { long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } textEditor.requestFocus(); }
From source file:org.totschnig.myexpenses.util.Utils.java
public static void share(Context ctx, ArrayList<Uri> fileUris, String target, String mimeType) { URI uri = null;//ww w .j a v a2s . c o m Intent intent; String scheme = "mailto"; boolean multiple = fileUris.size() > 1; if (!target.equals("")) { uri = Utils.validateUri(target); if (uri == null) { Toast.makeText(ctx, ctx.getString(R.string.ftp_uri_malformed, target), Toast.LENGTH_LONG).show(); return; } scheme = uri.getScheme(); } // if we get a String that does not include a scheme, // we interpret it as a mail address if (scheme == null) { scheme = "mailto"; } if (scheme.equals("ftp")) { if (multiple) { Toast.makeText(ctx, "sending multiple file through ftp is not supported", Toast.LENGTH_LONG).show(); return; } intent = new Intent(android.content.Intent.ACTION_SENDTO); intent.putExtra(Intent.EXTRA_STREAM, fileUris.get(0)); intent.setDataAndType(android.net.Uri.parse(target), mimeType); if (!isIntentAvailable(ctx, intent)) { Toast.makeText(ctx, R.string.no_app_handling_ftp_available, Toast.LENGTH_LONG).show(); return; } ctx.startActivity(intent); } else if (scheme.equals("mailto")) { if (multiple) { intent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); ArrayList<Uri> uris = new ArrayList<>(); for (Uri fileUri : fileUris) { uris.add(fileUri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { intent = new Intent(android.content.Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, fileUris.get(0)); } intent.setType(mimeType); if (uri != null) { String address = uri.getSchemeSpecificPart(); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address }); } intent.putExtra(Intent.EXTRA_SUBJECT, R.string.export_expenses); if (!isIntentAvailable(ctx, intent)) { Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show(); return; } // if we got mail address, we launch the default application // if we are called without target, we launch the chooser // in order to make action more explicit if (uri != null) { ctx.startActivity(intent); } else { ctx.startActivity(Intent.createChooser(intent, ctx.getString(R.string.share_sending))); } } else { Toast.makeText(ctx, ctx.getString(R.string.share_scheme_not_supported, scheme), Toast.LENGTH_LONG) .show(); return; } }
From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java
private void onShareDocuments(ArrayList<DocumentInfo> docs) { Intent intent;/*from www . jav a 2s . com*/ if (docs.size() == 1) { final DocumentInfo doc = docs.get(0); intent = new Intent(Intent.ACTION_SEND); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType(doc.mimeType); intent.putExtra(Intent.EXTRA_STREAM, doc.derivedUri); } else if (docs.size() > 1) { intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // intent.addCategory(Intent.CATEGORY_DEFAULT); final ArrayList<String> mimeTypes = Lists.newArrayList(); final ArrayList<Uri> uris = Lists.newArrayList(); for (DocumentInfo doc : docs) { mimeTypes.add(doc.mimeType); uris.add(doc.derivedUri); } intent.setType(findCommonMimeType(mimeTypes)); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { return; } intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via)); startActivity(intent); }
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) *///w w w .j av a2 s. c o m private void Share() { tracer.debug("GpsMainActivity.Share"); try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); final ArrayList selectedItems = new ArrayList(); // Where we track the selected items AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the dialog title builder.setTitle(R.string.osm_pick_file) .setMultiChoiceItems(files, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { if (which == 0) { //Unselect all others ((AlertDialog) dialog).getListView().clearChoices(); ((AlertDialog) dialog).getListView().setItemChecked(which, isChecked); selectedItems.clear(); } else { //Unselect the settings item ((AlertDialog) dialog).getListView().setItemChecked(0, false); if (selectedItems.contains(0)) { selectedItems.remove(selectedItems.indexOf(0)); } } selectedItems.add(which); } else if (selectedItems.contains(which)) { // Else, if the item is already in the array, remove it selectedItems.remove(Integer.valueOf(which)); } } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (selectedItems.size() <= 0) { return; } final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.get(0).equals(0)) { tracer.debug("User selected location only"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Geotrackin (Android app): Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<Uri>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { selectedItems.clear(); } }); builder.create(); builder.show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { tracer.error("Share", ex); } }
From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java
private boolean handleDefaultIntent(final Intent intent) { if (intent == null) return false; final String action = intent.getAction(); mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action); final Uri data = intent.getData(); final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT); final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (extraStream != null) { new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false).execute(); } else if (data != null) { new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false).execute(); } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT)) { final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT); if (bitmap != null) { try { new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE).execute(); } catch (IOException e) { // ignore bitmap.recycle();// www . j a v a2 s .c om } } } mEditText.setText(getShareStatus(this, extraSubject, extraText)); final int selection_end = mEditText.length(); mEditText.setSelection(selection_end); return true; }
From source file:org.ozonecity.gpslogger2.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) *//*from w w w.j a va 2 s.co m*/ private void Share() { try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files) .positiveText(R.string.ok) .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() { @Override public boolean onSelection(MaterialDialog materialDialog, Integer[] integers, CharSequence[] charSequences) { List<Integer> selectedItems = Arrays.asList(integers); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.size() <= 0) { return false; } if (selectedItems.contains(0)) { intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<Uri>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } return true; } }).show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { tracer.error("Sharing problem", ex); } }
From source file:de.mkrtchyan.recoverytools.RecoveryTools.java
public void report(final boolean isCancelable) { final Dialog reportDialog = mNotifyer.createDialog(R.string.commentar, R.layout.dialog_comment, false, true);// w w w . j ava2s . com new Thread(new Runnable() { @Override public void run() { /** Creates a report Email including a Comment and important device infos */ final Button bGo = (Button) reportDialog.findViewById(R.id.bGo); bGo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS)) Toast.makeText(mContext, R.string.please_ads, Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, R.string.donate_to_support, Toast.LENGTH_SHORT).show(); try { ArrayList<File> files = new ArrayList<File>(); File TestResults = new File(mContext.getFilesDir(), "results.txt"); try { if (TestResults.exists()) { if (TestResults.delete()) { FileOutputStream fos = openFileOutput(TestResults.getName(), Context.MODE_PRIVATE); fos.write(("Recovery-Tools:\n\n" + mShell.execCommand( "ls -lR " + PathToRecoveryTools.getAbsolutePath()) + "\nCache Tree:\n" + mShell.execCommand("ls -lR /cache") + "\n" + "\nMTD result:\n" + mShell.execCommand("cat /proc/mtd") + "\n" + "\nDevice Tree:\n\n" + mShell.execCommand("ls -lR /dev")) .getBytes()); } files.add(TestResults); } } catch (FileNotFoundException e) { e.printStackTrace(); } if (getPackageManager() != null) { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); EditText text = (EditText) reportDialog.findViewById(R.id.etComment); String comment = ""; if (text.getText() != null) comment = text.getText().toString(); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "ashotmkrtchyan1995@gmail.com" }); intent.putExtra(Intent.EXTRA_SUBJECT, "Recovery-Tools report"); intent.putExtra(Intent.EXTRA_TEXT, "Package Infos:" + "\n\nName: " + pInfo.packageName + "\nVersionName: " + pInfo.versionName + "\nVersionCode: " + pInfo.versionCode + "\n\n\nProduct Info: " + "\n\nManufacture: " + android.os.Build.MANUFACTURER + "\nDevice: " + Build.DEVICE + " (" + mDevice.getDeviceName() + ")" + "\nBoard: " + Build.BOARD + "\nBrand: " + Build.BRAND + "\nModel: " + Build.MODEL + "\nFingerprint: " + Build.FINGERPRINT + "\nAndroid SDK Level: " + Build.VERSION.CODENAME + " (" + Build.VERSION.SDK_INT + ")" + "\nRecovery Supported: " + mDevice.isRecoverySupported() + "\nRecovery Path: " + mDevice.getRecoveryPath() + "\nRecovery Version: " + mDevice.getRecoveryVersion() + "\nRecovery MTD: " + mDevice.isRecoveryMTD() + "\nRecovery DD: " + mDevice.isRecoveryDD() + "\nKernel Supported: " + mDevice.isKernelSupported() + "\nKernel Path: " + mDevice.getKernelPath() + "\nKernel Version: " + mDevice.getKernelVersion() + "\nKernel MTD: " + mDevice.isKernelMTD() + "\nKernel DD: " + mDevice.isKernelDD() + "\n\nCWM: " + mDevice.isCwmSupported() + "\nTWRP: " + mDevice.isTwrpSupported() + "\nPHILZ: " + mDevice.isPhilzSupported() + "\n\n\n===========COMMENT==========\n" + comment + "\n===========COMMENT END==========\n" + "\n===========PREFS==========\n" + getAllPrefs() + "\n===========PREFS END==========\n"); File CommandLogs = new File(mContext.getFilesDir(), Shell.Logs); if (CommandLogs.exists()) { files.add(CommandLogs); } files.add(new File(getFilesDir(), "last_log.txt")); ArrayList<Uri> uris = new ArrayList<Uri>(); for (File file : files) { mShell.execCommand("cp " + file.getAbsolutePath() + " " + new File(mContext.getFilesDir(), file.getName()).getAbsolutePath()); file = new File(mContext.getFilesDir(), file.getName()); mToolbox.setFilePermissions(file, "644"); uris.add(Uri.fromFile(file)); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(intent, "Send over Gmail")); reportDialog.dismiss(); } } catch (Exception e) { reportDialog.dismiss(); Notifyer.showExceptionToast(mContext, TAG, e); } } }); } }).start(); reportDialog.setCancelable(isCancelable); reportDialog.show(); }
From source file:usbong.android.utils.UsbongUtils.java
public static Intent performSendToCloudBasedServiceProcess(String filepath, List<String> filePathsList) { // final Intent sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND); final Intent sendToCloudBasedServiceIntent; if (filePathsList != null) { sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); } else {/* w w w . ja v a2s. co m*/ sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND); } try { InputStreamReader reader = UsbongUtils.getFileFromSDCardAsReader(filepath); BufferedReader br = new BufferedReader(reader); String currLineString; currLineString = br.readLine(); System.out.println(">>>>>>>>>> currLineString: " + currLineString); //Reference: http://blog.iangclifton.com/2010/05/17/sending-html-email-with-android-intent/ //last acccessed: 17 Jan. 2012 sendToCloudBasedServiceIntent.setType("text/plain"); sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "usbong;" + UsbongUtils.getDateTimeStamp()); sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_TEXT, currLineString); //body // sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"masarapmabuhay@gmail.com"});//"masarapmabuhay@gmail.com"); //only add path if it's not already in filePathsLists (i.e. attachmentFilePaths) if (!filePathsList.contains(filepath)) { filePathsList.add(filepath); } //Reference: http://stackoverflow.com/questions/2264622/android-multiple-email-attachments-using-intent //last accessed: 14 March 2012 //has to be an ArrayList ArrayList<Uri> uris = new ArrayList<Uri>(); //convert from paths to Android friendly Parcelable Uri's for (String file : filePathsList) { File fileIn = new File(file); if (fileIn.exists()) { //added by Mike, May 13, 2012 Uri u = Uri.fromFile(fileIn); uris.add(u); System.out.println(">>>>>>>>>>>>>>>>>> u: " + u); } } sendToCloudBasedServiceIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } catch (Exception e) { e.printStackTrace(); } return sendToCloudBasedServiceIntent; }
From source file:com.mb.android.MainActivity.java
public Intent getDraftWithProperties(String to, String subject, String body) { Intent mail = new Intent(Intent.ACTION_SEND_MULTIPLE); setSubject(subject, mail);/* w w w . j av a 2 s. co m*/ setBody(body, false, mail); setRecipients(to, mail); mail.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return mail; }