List of usage examples for android.content Intent FLAG_GRANT_READ_URI_PERMISSION
int FLAG_GRANT_READ_URI_PERMISSION
To view the source code for android.content Intent FLAG_GRANT_READ_URI_PERMISSION.
Click Source Link
From source file:com.agateau.equiv.ui.Kernel.java
public void shareCustomProductList(Context context) { File file = context.getFileStreamPath(CUSTOM_PRODUCTS_CSV); Uri contentUri = FileProvider.getUriForFile(context, "com.agateau.equiv.fileprovider", file); final Resources res = context.getResources(); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.CUSTOM_PRODUCTS_EMAIL }); intent.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.share_email_subject)); intent.putExtra(Intent.EXTRA_STREAM, contentUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); context.startActivity(Intent.createChooser(intent, res.getString(R.string.share_via))); }
From source file:ee.ria.DigiDoc.fragment.ContainerDataFilesFragment.java
private Uri createShareUri(String dataFileName) { File attachment = extractAttachment(dataFileName); if (attachment == null) { throw new FailedToCreateViewIntentException(getText(R.string.attachment_extract_failed)); }//from www . jav a 2 s . c o m Uri contentUri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, attachment); getContext().grantUriPermission(BuildConfig.APPLICATION_ID, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); return contentUri; }
From source file:com.renard.ocr.documents.creation.NewDocumentActivity.java
protected void startGallery() { mAnalytics.startGallery();// w w w .j a v a 2 s . com cameraPicUri = null; Intent i; if (Build.VERSION.SDK_INT >= 19) { i = new Intent(Intent.ACTION_GET_CONTENT, null); i.addCategory(Intent.CATEGORY_OPENABLE); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); i.setType("image/*"); i.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/png", "image/jpg", "image/jpeg" }); } else { i = new Intent(Intent.ACTION_GET_CONTENT, null); i.setType("image/png,image/jpg, image/jpeg"); } Intent chooser = Intent.createChooser(i, getString(R.string.image_source)); try { startActivityForResult(chooser, REQUEST_CODE_PICK_PHOTO); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.no_gallery_found, Toast.LENGTH_LONG).show(); } }
From source file:com.richtodd.android.quiltdesign.app.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case R.id.menu_settings: { Intent intent = new Intent(this, MainPreferenceActivity.class); startActivity(intent);//from ww w.ja v a 2 s . c o m return true; } case R.id.menu_about: { TextDialogFragment dialog = TextDialogFragment.create("About Quilt Design", getString(R.string.about), "Close"); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_help: { // Intent intent = new Intent(this, BrowserActivity.class); // intent.putExtra(BrowserActivity.ARG_URL, // "http://quiltdesign.richtodd.com"); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://quiltdesign.richtodd.com")); startActivity(intent); return true; } case R.id.menu_backup: { Uri uriFile; try { uriFile = saveRepository(); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uriFile); intent.setType("application/vnd.richtodd.quiltdesign"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, "Backup")); } catch (RepositoryException e) { Handle.asRuntimeError(e); } return true; } case R.id.menu_loadSamples: { SampleLoaderTask task = new SampleLoaderTask(); setSampleLoaderTask(task); task.execute(this); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.theaetetuslabs.android_apkmaker.InstallActivity.java
private void tryInstallInternal() { Log.d("TAG", "signed exists? " + files.signed.exists() + ", " + files.signed.getAbsolutePath()); System.out.println(BuildConfig.APPLICATION_ID + ".apkmakerfileprovider"); Uri contentUri = FileProvider.getUriForFile(this, getPackageName() + ".apkmakerfileprovider", files.signed); grantUriPermission("com.android.packageinstaller", contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent promptInstall = getInstallIntent(); promptInstall.setData(contentUri);//from www . ja v a 2 s .c om List<ResolveInfo> list = getPackageManager().queryIntentActivities(promptInstall, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { startActivityForResult(promptInstall, INSTALL_REQUEST); Log.d("TAG", "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Handled content URI"); } }
From source file:net.henryco.opalette.api.utils.Utils.java
public static void shareBitmapAction(Bitmap bitmap, String filename, Context activity, boolean saveAfter, Runnable... runnables) {//w ww. ja va 2 s. co m String file_name = filename; if (!file_name.endsWith(".png")) file_name += ".png"; try { File cachePath = new File(activity.getCacheDir(), "images"); // see: res/xml/filepaths.xml if (cachePath.exists()) deleteRecursive(cachePath); cachePath.mkdirs(); FileOutputStream stream = new FileOutputStream(cachePath + "/" + file_name); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); stream.close(); } catch (IOException e) { e.printStackTrace(); } File imagePath = new File(activity.getCacheDir(), "images"); File newFile = new File(imagePath, file_name); Uri contentUri = FileProvider.getUriForFile(activity, "net.henryco.opalette.fileprovider", newFile); if (contentUri != null) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file shareIntent.setType("image/png"); shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); activity.startActivity(Intent.createChooser(shareIntent, "Share")); } if (saveAfter) saveBitmapAction(bitmap, filename, activity, runnables); }
From source file:com.just.agentweb.AgentWebUtils.java
static void setIntentDataAndType(Context context, Intent intent, String type, File file, boolean writeAble) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType(getUriFromFile(context, file), type); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if (writeAble) { intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); }//from w ww . j av a2s.c om } else { intent.setDataAndType(Uri.fromFile(file), type); } }
From source file:org.cm.podd.report.activity.SettingActivity.java
private void cropImage() { Intent photoPickerIntent;/*www . j av a 2s. c o m*/ if (mCurrentPhotoUri == null) { // no photo to edit, then first select what to edit photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); photoPickerIntent.setType("image/*"); } else { // Edit photo after taken photoPickerIntent = new Intent("com.android.camera.action.CROP"); // indicate taken image type and Uri photoPickerIntent.setDataAndType(mCurrentPhotoUri, "image/*"); photoPickerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } photoPickerIntent.putExtra("crop", "true"); photoPickerIntent.putExtra("aspectX", 1); photoPickerIntent.putExtra("aspectY", 1); photoPickerIntent.putExtra("outputX", 400); photoPickerIntent.putExtra("outputY", 400); photoPickerIntent.putExtra("return-data", true); photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); startActivityForResult(photoPickerIntent, REQ_CODE_PICK_IMAGE); }
From source file:com.luongbui.andersenfestival.muzei.AndersenFestivalSource.java
@Override protected void onUpdate(int reason) { try {//from www. java 2 s .c o m int artIndex = loadArtIndex(); // Random if none exists. //android.util.Log.d("INDEX", ""+artIndex); if (reason == UPDATE_REASON_USER_NEXT || reason == UPDATE_REASON_SCHEDULED) { artIndex = incrArtIndex(artIndex); //android.util.Log.d("INDEX USER NEXT", ""+artIndex); } //For now, empty the external sub dir each time: TODO a more "flexible" cache system. deleteExternalSubdir(new File(getApplicationContext().getFilesDir(), PORTRAITS_SUBDIR)); File outFile = new File(getApplicationContext().getFilesDir(), PORTRAITS_SUBDIR + File.separator + PORTRAITS[artIndex].getFileName()); //TODO test if the file exits, should be false. //android.util.Log.d("TEST FILE EXISTS", ""+outFile.exists()+" : " + outFile.getPath()); copyAsset(PORTRAITS_SUBDIR, PORTRAITS[artIndex].getFileName()); //TODO test if the file exits, should be true. //android.util.Log.d("TEST FILE EXISTS", ""+outFile.exists()+" : " + outFile.getPath()); fileUri = FileProvider.getUriForFile(getApplicationContext(), FILE_PROVIDER_AUTHORITIES, outFile); Set<String> subscribers = prefs.getStringSet(SUBS_KEY, new TreeSet<String>()); for (String subPackage : subscribers) getApplicationContext().grantUriPermission(subPackage, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); //android.util.Log.d("SHARED FILE URI", ""+fileUri.toString()); publishArtwork(new Artwork.Builder().imageUri(fileUri).title(PORTRAITS[artIndex].getTitle()) .byline(PORTRAITS[artIndex].getByLine()) .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(PORTRAITS[artIndex].getAuthorUrl()))) .build()); // 12 Hours scheduleUpdate(System.currentTimeMillis() + 12 * 60 * 60 * 1000); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gov.wa.wsdot.android.wsdot.ui.CameraImageFragment.java
private Intent createShareIntent() { File f = new File(getActivity().getFilesDir(), mCameraName); ContentValues values = new ContentValues(2); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.DATA, f.getAbsolutePath()); Uri uri = getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.setType("image/jpeg"); shareIntent.putExtra(Intent.EXTRA_TEXT, mTitle); shareIntent.putExtra(Intent.EXTRA_SUBJECT, mTitle); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); return shareIntent; }