List of usage examples for android.content ClipData newRawUri
static public ClipData newRawUri(CharSequence label, Uri uri)
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.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. */// www . j a va 2s . co 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.getCrossProfileResult(intent); assertNotNull(result); 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 www . ja v 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
/** * This method will send an intent to a receiver in another profile. * This intent will have a message in an extra, and a uri specified by the ClipData. * The receiver will read the message from the extra, and write it to the uri in * the ClipData./*www. jav a2 s . c om*/ */ public void testReceiverCanWrite() throws Exception { // It's the receiver of the intent that should write to the uri, not us. So, for now, we // write an empty string. Uri uri = getUriWithTextInFile("writing_test", ""); assertTrue(uri != null); Intent intent = new Intent(ACTION_WRITE_TO_URI); intent.setClipData(ClipData.newRawUri("", uri)); intent.putExtra("extra_message", MESSAGE); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); mActivity.getResult(intent); assertEquals(MESSAGE, getFirstLineFromUri(uri)); }
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 a message in an extra, and a uri specified by the ClipData. * The receiver will read the message from the extra, and write it to the uri in * the ClipData.// w w w. j av a 2 s. c om */ public void testReceiverCanWrite() throws Exception { // It's the receiver of the intent that should write to the uri, not us. So, for now, we // write an empty string. Uri uri = getUriWithTextInFile("writing_test", ""); assertTrue(uri != null); Intent intent = new Intent(ACTION_WRITE_TO_URI); intent.setClipData(ClipData.newRawUri("", uri)); intent.putExtra("extra_message", MESSAGE); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); mActivity.getCrossProfileResult(intent); assertEquals(MESSAGE, getFirstLineFromUri(uri)); }
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 v a 2 s . co 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.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);// w w w . j av a 2 s . c om 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);/*from w ww . ja va 2s .c om*/ assertEquals(MESSAGE, result.getStringExtra("extra_response")); }
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 w w. j a v a 2 s.c o 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.android.cts.intent.sender.IntentSenderTest.java
/** * The intent receiver will try to read uriNotGranted. * Inside the same user, this uri can be read if the receiver has the * com.android.cts.managedprofile.permission.SAMPLE permission. But since we cross * user-boundaries, it should not be able to (only uri grants work accross users for apps * without special permission).//from w w w.j a va 2 s.co m * We also grant uriGranted to the receiver (this uri belongs to the same content provider as * uriNotGranted), to enforce that even if an app has permission to one uri of a * ContentProvider, it still cannot access a uri it does not have access to. */ public void testAppPermissionsDontWorkAcrossProfiles() throws Exception { // The FileProvider does not allow to use app permissions. So we need to use another // ContentProvider. Uri uriGranted = getBasicContentProviderUri("uri_granted"); Uri uriNotGranted = getBasicContentProviderUri("uri_not_granted"); // Granting uriGranted to the receiver // Using a persistable permission so that it is kept even after we restart the receiver // activity with another intent. grantPersistableReadPermission(uriGranted); Intent notGrant = new Intent(ACTION_READ_FROM_URI); notGrant.setClipData(ClipData.newRawUri("", uriNotGranted)); final Intent result = mActivity.getResult(notGrant); assertNotNull(result); // The receiver did not have permission to read the uri. So it should have caught a security // exception. assertTrue(result.getBooleanExtra("extra_caught_security_exception", false)); }