List of usage examples for android.content Intent putParcelableArrayListExtra
public @NonNull Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
From source file:com.swisscom.safeconnect.activity.DashboardActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_show_log: Intent logIntent = new Intent(this, LogActivity.class); startActivity(logIntent);/*from w w w .j ava2 s.c o m*/ return true; case R.id.menu_send_log: File log = Logger.saveLogs(this); File charonlog = new File(getFilesDir(), CharonVpnService.LOG_FILE); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "manuel.cianci1@swisscom.com" }); intent.putExtra(Intent.EXTRA_SUBJECT, "PipeOfTrust LogFiles"); intent.setType("text/plain"); ArrayList<Uri> files = new ArrayList<Uri>(); if (charonlog.exists() && charonlog.length() > 0) { files.add(LogContentProvider.createContentUri()); } if (log.exists() && log.length() > 0) { files.add(Uri.fromFile(log)); } if (files.size() == 0) { Toast.makeText(this, "Log is empty!", Toast.LENGTH_SHORT).show(); return true; } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); startActivity(Intent.createChooser(intent, getString(R.string.send_log))); return true; case R.id.menu_change_num: if (mService.getState() == VpnStateService.State.CONNECTED) { mService.disconnect(); } intent = new Intent(this, RegistrationActivity.class); intent.putExtra(RegistrationActivity.FORCE_ACTIVITY, true); startActivity(intent); finish(); return true; case R.id.menu_help: startActivity(new Intent(this, FaqActivity.class)); return true; case R.id.menu_settings: Intent settingsIntent = new Intent(this, SettingsActivity.class); startActivity(settingsIntent); return true; case R.id.menu_share: share(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.dycody.android.idealnote.MainActivity.java
/** * Notes sharing// w w w . j ava2s . co m */ public void shareNote(Note note) { String titleText = note.getTitle(); String contentText = titleText + System.getProperty("line.separator") + note.getContent(); Intent shareIntent = new Intent(); // Prepare sharing intent with only text if (note.getAttachmentsList().size() == 0) { shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); // Intent with single image attachment } else if (note.getAttachmentsList().size() == 1) { shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(note.getAttachmentsList().get(0).getMime_type()); shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri()); // Intent with multiple images } else if (note.getAttachmentsList().size() > 1) { shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); ArrayList<Uri> uris = new ArrayList<>(); // A check to decide the mime type of attachments to share is done here HashMap<String, Boolean> mimeTypes = new HashMap<>(); for (Attachment attachment : note.getAttachmentsList()) { uris.add(attachment.getUri()); mimeTypes.put(attachment.getMime_type(), true); } // If many mime types are present a general type is assigned to intent if (mimeTypes.size() > 1) { shareIntent.setType("*/*"); } else { shareIntent.setType((String) mimeTypes.keySet().toArray()[0]); } shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText); shareIntent.putExtra(Intent.EXTRA_TEXT, contentText); startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser))); }
From source file:com.duy.pascal.ui.file.FileExplorerAction.java
private void shareFile() { if (mCheckedList.isEmpty() || mShareActionProvider == null) return;/*from w w w . j av a 2s .c o m*/ try { Intent shareIntent = new Intent(); if (mCheckedList.size() == 1) { File file = new File(mCheckedList.get(0).getPath()); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(MimeTypes.getInstance().getMimeType(file.getPath())); Uri fileUri; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { fileUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", file); } else { fileUri = Uri.fromFile(file); } shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); ArrayList<Uri> streams = new ArrayList<>(); for (File file : mCheckedList) { File File = new File(file.getPath()); Uri fileUri; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { fileUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", File); } else { fileUri = Uri.fromFile(File); } streams.add(fileUri); } shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, streams); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } mShareActionProvider.setShareIntent(shareIntent); } catch (Exception ignored) { ignored.printStackTrace(); } }
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 . ja v a 2 s . 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:ac.robinson.mediaphone.MediaPhoneActivity.java
private void sendFiles(final ArrayList<Uri> filesToSend) { // send files in a separate task without a dialog so we don't leave the previous progress dialog behind on // screen rotation - this is a bit of a hack, but it works runImmediateBackgroundTask(new BackgroundRunnable() { @Override//from w ww . j a v a 2s . com public int getTaskId() { return 0; } @Override public boolean getShowDialog() { return false; } @Override public void run() { if (filesToSend == null || filesToSend.size() <= 0) { return; } // ensure files are accessible to send - bit of a last-ditch effort for when temp is on internal storage for (Uri fileUri : filesToSend) { IOUtilities.setFullyPublic(new File(fileUri.getPath())); } // also see: http://stackoverflow.com/questions/2344768/ // could use application/smil+xml (or html), or video/quicktime, but then there's no bluetooth option final Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); sendIntent.setType(getString(R.string.export_mime_type)); sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend); final Intent chooserIntent = Intent.createChooser(sendIntent, getString(R.string.export_narrative_title)); // an extra activity at the start of the list that moves exported files to SD, but only if SD available if (IOUtilities.externalStorageIsWritable()) { final Intent targetedShareIntent = new Intent(MediaPhoneActivity.this, SaveNarrativeActivity.class); targetedShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); targetedShareIntent.setType(getString(R.string.export_mime_type)); targetedShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { targetedShareIntent }); } startActivity(chooserIntent); // single task mode; no return value given } }); }
From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java
/** * Finishes this activity when save-as.//from ww w .j av a2 s. co m * * @param file * @link Uri. */ private void finish(Uri file, boolean fileExists) { ArrayList<Uri> list = new ArrayList<Uri>(); list.add(file); Intent intent = new Intent(); intent.setData(file); intent.putParcelableArrayListExtra(FileChooserActivity.EXTRA_RESULTS, list); intent.putExtra(FileChooserActivity.EXTRA_RESULT_FILE_EXISTS, fileExists); getActivity().setResult(FileChooserActivity.RESULT_OK, intent); getActivity().finish(); }
From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java
/** * Finishes this activity./*from w ww . ja v a 2s . co m*/ * * @param files * list of {@link Uri}. */ private void finish(ArrayList<Uri> files) { if (files == null || files.isEmpty()) { getActivity().setResult(Activity.RESULT_CANCELED); getActivity().finish(); return; } Intent intent = new Intent(); if (files.size() == 1) { intent.setData(files.get(0)); } intent.putParcelableArrayListExtra(FileChooserActivity.EXTRA_RESULTS, files); getActivity().setResult(FileChooserActivity.RESULT_OK, intent); if (DisplayPrefs.isRememberLastLocation(getActivity()) && getCurrentLocation() != null) DisplayPrefs.setLastLocation(getActivity(), getCurrentLocation().toString()); else DisplayPrefs.setLastLocation(getActivity(), null); getActivity().finish(); }
From source file:com.haibison.android.anhuu.FragmentFiles.java
/** * Finishes this activity.//from w w w . ja v a 2 s . c o m * * @param files * list of {@link Uri}. */ private void finish(ArrayList<Uri> files) { if (files == null || files.isEmpty()) { getActivity().setResult(Activity.RESULT_CANCELED); getActivity().finish(); return; } Intent intent = new Intent(); intent.putParcelableArrayListExtra(FileChooserActivity.EXTRA_RESULTS, files); getActivity().setResult(FileChooserActivity.RESULT_OK, intent); saveSettingsAndFinish(); }
From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java
private void onShareDocuments(ArrayList<DocumentInfo> docs) { Intent intent; 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);// w w w . j av a 2 s . c o m 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:org.brandroid.openmanager.util.EventHandler.java
public void sendFile(final Collection<OpenPath> path, final Context mContext) { String name;/* ww w. ja va 2 s . c o m*/ CharSequence[] list = { "Bluetooth", "Email" }; final OpenPath[] files = new OpenPath[path.size()]; path.toArray(files); final int num = path.size(); if (num == 1) name = files[0].getName(); else name = path.size() + " " + getResourceString(mContext, R.string.s_files) + "."; AlertDialog.Builder b = new AlertDialog.Builder(mContext); b.setTitle(getResourceString(mContext, R.string.s_title_send).toString().replace("xxx", name)) .setIcon(R.drawable.bluetooth).setItems(list, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: Intent bt = new Intent(mContext, BluetoothActivity.class); bt.putExtra("paths", files); mContext.startActivity(bt); break; case 1: ArrayList<Uri> uris = new ArrayList<Uri>(); Intent mail = new Intent(); mail.setType("application/mail"); if (num == 1) { mail.setAction(android.content.Intent.ACTION_SEND); mail.putExtra(Intent.EXTRA_STREAM, files[0].getUri()); mContext.startActivity(mail); break; } for (int i = 0; i < num; i++) uris.add(files[i].getUri()); mail.setAction(android.content.Intent.ACTION_SEND_MULTIPLE); mail.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); mContext.startActivity(mail); break; } } }).create().show(); }