ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newRawUri(null, contentUri)); intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
void onTaskFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]); } else if (uris.length > 1) { final ClipData clipData = new ClipData( null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } intent.setClipData(clipData); }
private void showCamera() { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "DCIM"); if (!file.exists()) { file.mkdirs(); } File localFile2 = new File(file + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"); imageUri = Uri.fromFile(localFile2); Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE"); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { cameraIntent.setClipData(ClipData.newRawUri(null, Uri.fromFile(localFile2))); } startActivityForResult(cameraIntent, REQUEST_CAMERA); } catch (Exception localException) { Toast.makeText(ActivityAddMemory.this, "Exception:" + localException, Toast.LENGTH_SHORT).show(); } }
private void selectFromCamera() { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "DCIM"); if (!file.exists()) { file.mkdirs(); } File localFile = new File(file + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"); imageUri = Uri.fromFile(localFile); Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE"); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { cameraIntent.setClipData(ClipData.newRawUri(null, Uri.fromFile(localFile))); } startActivityForResult(cameraIntent, REQUEST_CAMERA); } catch (Exception localException) { Toast.makeText(ActivityAddMemory.this, "Exception:" + localException, Toast.LENGTH_SHORT).show(); } } private void selectFromGallery() { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); }
@VisibleForTesting public static Intent getShareIntent(String title, String url, Uri screenshotUri) { url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); Intent intent = new Intent(Intent.ACTION_SEND); intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag()); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, url); if (screenshotUri != null) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // To give read access to an Intent target, we need to put |screenshotUri| in clipData // because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for // EXTRA_SHARE_SCREENSHOT_AS_STREAM. intent.setClipData(ClipData.newRawUri("", screenshotUri)); intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri); } return intent; }
static void addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs, Intent intent, Bundle results) { Bundle resultsBundle = new Bundle(); for (RemoteInputCompatBase.RemoteInput remoteInput : remoteInputs) { Object result = results.get(remoteInput.getResultKey()); if (result instanceof CharSequence) { resultsBundle.putCharSequence(remoteInput.getResultKey(), (CharSequence) result); } } Intent clipIntent = new Intent(); clipIntent.putExtra(EXTRA_RESULTS_DATA, resultsBundle); intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipIntent)); } }
ClipData.newUri(activity.getContentResolver(), "a Video", videoFileUri); videoIntent.setClipData(clip); videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ClipData.newUri(activity.getContentResolver(), "a Photo", capturedImageUri); cameraIntent.setClipData(clip); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
@Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri.Builder b = new Uri.Builder(); b.scheme("content"); b.authority("com.example.android.apis.content.FileProvider"); TypedValue tv = new TypedValue(); getResources().getValue(R.drawable.jellies, tv, true); b.appendEncodedPath(Integer.toString(tv.assetCookie)); b.appendEncodedPath(tv.string.toString()); Uri uri = b.build(); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setClipData(ClipData.newUri(getContentResolver(), "image", uri)); startActivity(Intent.createChooser(intent, "Select share target")); } });
@Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri.Builder b = new Uri.Builder(); b.scheme("content"); b.authority("com.example.android.apis.content.FileProvider"); TypedValue tv = new TypedValue(); getResources().getValue(R.drawable.jellies, tv, true); b.appendEncodedPath(Integer.toString(tv.assetCookie)); b.appendEncodedPath(tv.string.toString()); Uri uri = b.build(); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setClipData(ClipData.newUri(getContentResolver(), "image", uri)); startActivity(Intent.createChooser(intent, "Select share target")); } });
/** * Creates intent and executes request. * * @param intentBuilder - contains intent parameters. */ private void sendRequest(OsmAndIntentBuilder intentBuilder) { try { Uri uri = intentBuilder.getUri(); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addFlags(intentBuilder.getFlags()); Map<String, String> extraData = intentBuilder.getExtraData(); if (extraData != null) { for (String key : extraData.keySet()) { intent.putExtra(key, extraData.get(key)); } } if (intentBuilder.getGpxUri() != null) { ClipData clipData = ClipData.newRawUri("Gpx", intentBuilder.getGpxUri()); intent.setClipData(clipData); } if (isIntentSafe(intent)) { mActivity.startActivityForResult(intent, mRequestCode); } else { mOsmandMissingListener.osmandMissing(); } } catch (Exception e) { Toast.makeText(mActivity, e.getMessage(), Toast.LENGTH_LONG).show(); } }
ClipData.newUri(getContentResolver(), "a Video", videoFileUri); videoIntent.setClipData(clip); videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ClipData.newUri(getContentResolver(), "a Photo", capturedImageUri); cameraIntent.setClipData(clip); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onFilesPicked(@NonNull final List<Uri> files) { Intent i = new Intent(); i.putExtra(EXTRA_ALLOW_MULTIPLE, true); // Set as String Extras for all versions ArrayList<String> paths = new ArrayList<>(); for (Uri file : files) { paths.add(file.toString()); } i.putStringArrayListExtra(EXTRA_PATHS, paths); // Set as Clip Data for Jelly bean and above if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = null; for (Uri file : files) { if (clip == null) { clip = new ClipData("Paths", new String[]{}, new ClipData.Item(file)); } else { clip.addItem(new ClipData.Item(file)); } } i.setClipData(clip); } setResult(Activity.RESULT_OK, i); finish(); }
ClipData.newUri(getContentResolver(), "a Photo", uri); shareIntent.setClipData(clip); shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setClipData(clipData);
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]); } else if (uris.length > 1) { final ClipData clipData = new ClipData( null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } if(Utils.hasJellyBean()){ intent.setClipData(clipData); } else{ intent.setData(uris[0]); } } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); setResult(Activity.RESULT_OK, intent); finish(); } private class CreateFinishTask extends AsyncTask<Void, Void, Uri> {
public void setPhotosResult() { final AlbumItem[] selected_items = SelectorModeManager .createAlbumItemArray(recyclerViewAdapter.cancelSelectorMode(this)); Intent intent = new Intent("us.koller.RESULT_ACTION"); if (allowMultiple) { ClipData clipData = createClipData(selected_items); intent.setClipData(clipData); } else { intent.setData(selected_items[0].getUri(this)); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); setResult(RESULT_OK, intent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { finishAfterTransition(); } else { finish(); } }
ClipData.newUri(getActivity().getContentResolver(), "a Photo", capturedImageUri); cameraIntent.setClipData(clip); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);