List of usage examples for android.content Intent setClipData
public void setClipData(@Nullable ClipData clip)
From source file:Main.java
private static void addPhotoPickerExtras(Intent intent, Uri photoUri) { intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, photoUri)); }
From source file:com.android.contacts.util.ContactPhotoUtils.java
/** * Adds common extras to gallery intents. * * @param intent The intent to add extras to. * @param photoUri The uri of the file to save the image to. *///from w ww .j ava 2 s. co m public static void addPhotoPickerExtras(Intent intent, Uri photoUri) { intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, photoUri)); }
From source file:com.silentcircle.contacts.utils.ContactPhotoUtils19.java
/** * Adds common extras to gallery intents. * * @param intent The intent to add extras to. * @param photoUri The uri of the file to save the image to. *//*from w ww . ja v a 2 s .c o m*/ @TargetApi(Build.VERSION_CODES.KITKAT) public static void addPhotoPickerExtras(Intent intent, Uri photoUri) { intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, photoUri)); }
From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java
public static void launchExternalViewer(Activity activity, String fileUrl) { Intent intent = new Intent(Intent.ACTION_VIEW); String extension = MimeTypeMap.getFileExtensionFromUrl(fileUrl); String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (!TextUtils.isEmpty(type)) { String filePath = fileUrl; if (filePath.startsWith("file:")) { filePath = filePath.substring("file:".length()); }// w w w . ja v a 2 s . c om Uri photoUri = FileProvider.getUriForFile(activity, activity.getPackageName(), new File(filePath)); intent.setDataAndType(photoUri, type); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Needed to avoid security exception on KitKat. intent.setClipData(ClipData.newRawUri(null, photoUri)); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { activity.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "No activity found to handle this " + fileUrl + " type " + type); } } else { Log.w(TAG, "Could not find mime type for " + fileUrl); } }
From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java
private static String capturePictureLabel(Context context, IStartable startable) { // Starts a picture intent. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) { File photoFile = null;//from w w w .j a va 2 s. c o m try { photoFile = PictureUtils.createImageFile( AppSingleton.getInstance(context).getSensorEnvironment().getDefaultClock().getNow()); } catch (IOException ex) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, ex.getMessage()); } } if (photoFile != null) { Uri photoUri = FileProvider.getUriForFile(context, context.getPackageName(), photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Needed to avoid security exception on KitKat. takePictureIntent.setClipData(ClipData.newRawUri(null, photoUri)); } takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); String pictureLabelPath = "file:" + photoFile.getAbsoluteFile(); startable.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); return pictureLabelPath; } } return null; }
From source file:com.ultramegasoft.flavordex2.util.PhotoUtils.java
/** * Get an Intent to capture a photo.// ww w.j ava 2 s . c om * * @return Image capture Intent */ @Nullable public static Intent getTakePhotoIntent(@NonNull Context context) { try { final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", getOutputMediaFile()); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { intent.setClipData(ClipData.newUri(context.getContentResolver(), null, uri)); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { final List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo activity : activities) { final String name = activity.activityInfo.packageName; context.grantUriPermission(name, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } return intent; } catch (IOException e) { Log.e(TAG, "Failed to create new file", e); } return null; }
From source file:com.android.cts.intent.sender.ContentTest.java
/** * This method will send an intent to a receiver in another profile. * This intent will have, in the ClipData, a uri whose associated file stores a message. * The receiver will read the message from the uri, and put it inside the result intent. *//*from w w w.j a v a 2 s . c om*/ public void testReceiverCanRead() throws Exception { Uri uri = getUriWithTextInFile("reading_test", MESSAGE); assertTrue(uri != null); Intent intent = new Intent(ACTION_READ_FROM_URI); intent.setClipData(ClipData.newRawUri("", uri)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); final Intent result = mActivity.getCrossProfileResult(intent); assertNotNull(result); assertEquals(MESSAGE, result.getStringExtra("extra_response")); }
From source file:com.android.cts.intent.sender.ContentTest.java
public void testPersistablePermission() throws Exception { Uri uri = getUriWithTextInFile("persistable_test", MESSAGE); grantPersistableReadPermission(uri); // Now checking if the receiver can read this uri, without re-granting the read permission. Intent intent = new Intent(ACTION_READ_FROM_URI); intent.setClipData(ClipData.newRawUri("", uri)); final Intent result = mActivity.getCrossProfileResult(intent); assertNotNull(result);//ww w .jav a 2 s .co m assertEquals(MESSAGE, result.getStringExtra("extra_response")); }
From source file:com.android.cts.intent.sender.IntentSenderTest.java
/** * This method will send an intent to a receiver in another profile. * This intent will have, in the ClipData, a uri whose associated file stores a message. * The receiver will read the message from the uri, and put it inside the result intent. *//*from w w w. j av a 2 s.c o m*/ public void testReceiverCanRead() throws Exception { Uri uri = getUriWithTextInFile("reading_test", MESSAGE); assertTrue(uri != null); Intent intent = new Intent(ACTION_READ_FROM_URI); intent.setClipData(ClipData.newRawUri("", uri)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); final Intent result = mActivity.getResult(intent); assertNotNull(result); assertEquals(MESSAGE, result.getStringExtra("extra_response")); }
From source file:com.android.cts.intent.sender.IntentSenderTest.java
public void testPersistablePermission() throws Exception { Uri uri = getUriWithTextInFile("persistable_test", MESSAGE); grantPersistableReadPermission(uri); // Now checking if the receiver can read this uri, without re-granting the read permission. Intent intent = new Intent(ACTION_READ_FROM_URI); intent.setClipData(ClipData.newRawUri("", uri)); final Intent result = mActivity.getResult(intent); assertNotNull(result);// www.jav a 2 s . co m assertEquals(MESSAGE, result.getStringExtra("extra_response")); }