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.uphyca.kitkat.storage.ui.MainFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override// w ww . j a va 2 s.c om public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Activity.RESULT_OK && data.getData() != null) { int takeFlags = data.getFlags(); takeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. getActivity().getContentResolver().takePersistableUriPermission(data.getData(), takeFlags); } switch (requestCode) { case REQUEST_OPEN: onOpenRequestResult(resultCode, data); return; case REQUEST_EDIT: case REQUEST_CREATE: onEditRequestResult(resultCode, data); return; case REQUEST_DELETE: onDeleteRequestResult(resultCode, data); return; default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.nuvolect.securesuite.data.ExportVcf.java
public static void emailVcf(Activity act, long contact_id) { String messageTitle = "vCard for "; String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager"; try {//w w w. j a va2s . c o m String displayName = SqlCipher.get(contact_id, ATab.display_name); String fileName = displayName.replaceAll("\\W+", ""); if (fileName.isEmpty()) fileName = "contact"; fileName = fileName + ".vcf"; new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs(); File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName); writeContactVcard(contact_id, vcf_file); // Must match "authorities" in Manifest provider definition String authorities = act.getResources().getString(R.string.app_authorities) + ".provider"; Uri uri = null; try { uri = FileProvider.getUriForFile(act, authorities, vcf_file); } catch (IllegalArgumentException e) { LogUtil.logException(act, LogType.EXPORT_VCF, e); } //convert from paths to Android friendly Parcelable Uri's ArrayList<Uri> uris = new ArrayList<Uri>(); uris.add(uri); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName); intent.putExtra(Intent.EXTRA_TEXT, messageBody); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("path", vcf_file.getAbsolutePath()); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); act.startActivityForResult(Intent.createChooser(intent, "Share with..."), CConst.RESPONSE_CODE_SHARE_VCF); } catch (Exception e) { LogUtil.logException(act, LogType.EXPORT_VCF, e); } }
From source file:com.avalon.share.ShareHelper.java
private static void internalShareFile(String text, String longText, File file) { // let the FileProvider generate an URI for this private file final Uri uri = FileProvider.getUriForFile(activity, activity.getPackageName() + ".fileprovider", file); String resultText = text + " " + "https://play.google.com/store/apps/details?id=" + activity.getPackageName(); if (_hashTag.length() != 0) resultText = resultText + " #" + _hashTag; // create an intent, so the user can choose which application he/she wants to use to share this file final Intent intent = ShareCompat.IntentBuilder.from(activity).setType("image/*") //.setSubject(this.getString(R.string.share_subject)) .setStream(uri).setText(resultText) //.setChooserTitle(R.string.share_title) .createChooserIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivity(intent);/*from www . j av a 2 s . c o m*/ }
From source file:info.schnatterer.logbackandroiddemo.SendLogActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Get URIs for log files using android.support.v4.content.FileProvider */ ArrayList<Uri> uris = new ArrayList<>(); for (final File fileEntry : Logs.getLogFiles(this)) { // Don't recurse! if (!fileEntry.isDirectory()) { // Create content provider URI uris.add(FileProvider.getUriForFile(this, getString(R.string.authority_log_file_provider), fileEntry));/*from ww w . ja v a 2s. co m*/ } } final Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE); email.setType("message/rfc822"); email.putExtra(Intent.EXTRA_EMAIL, new String[] { "a@b.c" }); email.putExtra(Intent.EXTRA_SUBJECT, getString(getApplicationInfo().labelRes)); email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); email.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(email); finish(); }
From source file:com.github.czy1121.update.app.utils.UpdateUtil.java
public static void install(Context context, File file, boolean force) { Intent intent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); } else {/*from w ww .ja v a2 s. c o m*/ Uri uri = FileProvider.getUriForFile(context, context.getPackageName() + ".updatefileprovider", file); intent.setDataAndType(uri, "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); if (force) { System.exit(0); } }
From source file:com.teegarcs.mocker.internals.MockerInternals.java
public static Intent generateShareViewIntent(Context context, Uri uri) { //share intent Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(context.getContentResolver().getType(uri)); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //view intent Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(uri);/* ww w . j a v a 2 s.c om*/ viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent chooserIntent = Intent.createChooser(shareIntent, "Share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { viewIntent }); return chooserIntent; }
From source file:com.owncloud.android.ui.helpers.FileOperationsHelper.java
public void openFile(OCFile file) { if (file != null) { String storagePath = file.getStoragePath(); Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW); intentForSavedMimeType.setDataAndType(file.getExposedFileUri(mFileActivity), file.getMimetype()); intentForSavedMimeType//from w w w.j a v a 2 s . c om .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); Intent intentForGuessedMimeType = null; if (storagePath.lastIndexOf('.') >= 0) { String guessedMimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) { intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW); intentForGuessedMimeType.setDataAndType(file.getExposedFileUri(mFileActivity), guessedMimeType); intentForGuessedMimeType.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } Intent openFileWithIntent; if (intentForGuessedMimeType != null) { openFileWithIntent = intentForGuessedMimeType; } else { openFileWithIntent = intentForSavedMimeType; } List<ResolveInfo> launchables = mFileActivity.getPackageManager() .queryIntentActivities(openFileWithIntent, PackageManager.GET_INTENT_FILTERS); if (launchables != null && launchables.size() > 0) { try { mFileActivity.startActivity(Intent.createChooser(openFileWithIntent, mFileActivity.getString(R.string.actionbar_open_with))); } catch (ActivityNotFoundException anfe) { mFileActivity .showSnackMessage(mFileActivity.getString(R.string.file_list_no_app_for_file_type)); } } else { mFileActivity.showSnackMessage(mFileActivity.getString(R.string.file_list_no_app_for_file_type)); } } else { Log_OC.e(TAG, "Trying to open a NULL OCFile"); } }
From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == OPEN_DIRECTORY_REQUEST_CODE && resultCode == Activity.RESULT_OK) { getActivity().getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); updateDirectoryEntries(data.getData()); }/*from w w w . jav a 2 s . c o m*/ }
From source file:com.commonsware.android.documents.consumer.ConsumerFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (resultCode == Activity.RESULT_OK) { getActivity().startService(new Intent(getActivity(), DurablizerService.class) .setData(resultData.getData()).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)); }//from w w w . java2 s . c om }
From source file:com.cerema.cloud2.files.FileOperationsHelper.java
public void openFile(OCFile file) { if (file != null) { String storagePath = file.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW); intentForSavedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath), file.getMimetype()); intentForSavedMimeType/* ww w. ja va2 s. c o m*/ .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); Intent intentForGuessedMimeType = null; if (storagePath.lastIndexOf('.') >= 0) { String guessedMimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) { intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW); intentForGuessedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath), guessedMimeType); intentForGuessedMimeType.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } Intent openFileWithIntent; if (intentForGuessedMimeType != null) { openFileWithIntent = intentForGuessedMimeType; } else { openFileWithIntent = intentForSavedMimeType; } List<ResolveInfo> launchables = mFileActivity.getPackageManager() .queryIntentActivities(openFileWithIntent, PackageManager.GET_INTENT_FILTERS); if (launchables != null && launchables.size() > 0) { try { mFileActivity.startActivity(Intent.createChooser(openFileWithIntent, mFileActivity.getString(R.string.actionbar_open_with))); } catch (ActivityNotFoundException anfe) { showNoAppForFileTypeToast(mFileActivity.getApplicationContext()); } } else { showNoAppForFileTypeToast(mFileActivity.getApplicationContext()); } } else { Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); } }