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:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private void dispatchTakePictureIntent() { createIfNotExists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(file -> {/* ww w. ja v a2 s . c o m*/ if (file.exists()) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp file.", file.getAbsolutePath())); } if (view.isAvailable()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(view.getContext().getPackageManager()) != null) { this.tempTakenPhoto = file;//set it in property Uri uri = FileProvider.getUriForFile(view.getContext(), GRANT_PERMISSION, file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //fileProvider requires gran permission to others access that uri if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { final Context context = view.getContext(); List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (infos != null) { StreamSupport.stream(infos).filter(x -> x.activityInfo != null) .map(x -> x.activityInfo.packageName).forEach(pack -> { context.grantUriPermission(pack, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }); } } view.startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { view.showError("You need to install app that can capture photo."); } } }, this::log); }
From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { downloaderBinder.cancel(mAccount, mFile); if (mFile.isDown()) { setButtonsForDown();/*from w w w. j av a2 s .com*/ } else { setButtonsForRemote(); } } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) { uploaderBinder.cancel(mAccount, mFile); if (!mFile.fileExists()) { // TODO make something better if (getActivity() instanceof FileDisplayActivity) { // double pane FragmentTransaction transaction = getActivity().getSupportFragmentManager() .beginTransaction(); transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment transaction.commit(); mContainerActivity.onFileStateChanged(); } else { getActivity().finish(); } } else if (mFile.isDown()) { setButtonsForDown(); } else { setButtonsForRemote(); } } else { mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity()); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); mLastRemoteOperation.execute(wc, this, mHandler); // update ui boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().showDialog((inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference } break; } case R.id.fdKeepInSync: { CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); mFile.setKeepInSync(cb.isChecked()); mStorageManager.saveFile(mFile); /// register the OCFile instance in the observer service to monitor local updates; /// if necessary, the file is download Intent intent = new Intent(getActivity().getApplicationContext(), FileObserverService.class); intent.putExtra(FileObserverService.KEY_FILE_CMD, (cb.isChecked() ? FileObserverService.CMD_ADD_OBSERVED_FILE : FileObserverService.CMD_DEL_OBSERVED_FILE)); intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile); intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount); Log.e(TAG, "starting observer service"); getActivity().startService(intent); if (mFile.keepInSync()) { onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization } break; } case R.id.fdRenameBtn: { EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this); dialog.show(getFragmentManager(), "nameeditdialog"); break; } case R.id.fdRemoveBtn: { ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( R.string.confirmation_remove_alert, new String[] { mFile.getFileName() }, mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote, mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel); confDialog.setOnConfirmationListener(this); mCurrentDialog = confDialog; mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION); break; } case R.id.fdOpenBtn: { String storagePath = mFile.getStoragePath(); String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mFile.getMimetype()); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); } catch (Throwable t) { Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype()); boolean toastIt = true; String mimeType = ""; try { Intent i = new Intent(Intent.ACTION_VIEW); mimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); if (mimeType == null || !mimeType.equals(mFile.getMimetype())) { if (mimeType != null) { i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mimeType); } else { // desperate try i.setDataAndType(Uri.parse("file://" + encodedStoragePath), "*/*"); } i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); toastIt = false; } } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath); } catch (ActivityNotFoundException e) { Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension"); } catch (Throwable th) { Log.e(TAG, "Unexpected problem when opening: " + storagePath, th); } finally { if (toastIt) { Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT) .show(); } } } break; } default: Log.e(TAG, "Incorrect view clicked!"); } /* else if (v.getId() == R.id.fdShareBtn) { Thread t = new Thread(new ShareRunnable(mFile.getRemotePath())); t.start(); }*/ }
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override/*from w w w. j a v a 2s. com*/ protected void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (resultCode == RESULT_OK && requestCode == this.RESULT_ADD_PEER) { byte[] _pi = resultData.getByteArrayExtra(AddSafe.PI); net.ddp2p.common.hds.PeerInput pi = null; if (_pi != null) try { pi = new PeerInput().decode(new Decoder(_pi)); } catch (Exception e) { e.printStackTrace(); } if (pi == null) pi = Safe.peerInput; new PeerCreatingThread(pi).start(); super.onActivityResult(requestCode, resultCode, resultData); return; } if (resultCode == RESULT_OK && resultData != null) { Uri uri = null; if (requestCode == SELECT_PHOTO) { uri = resultData.getData(); Log.i("Uri", "Uri: " + uri.toString()); } else if (requestCode == SELECT_PHOTO_KITKAT) { uri = resultData.getData(); Log.i("Uri_kitkat", "Uri: " + uri.toString()); final int takeFlags = resultData.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. getContentResolver().takePersistableUriPermission(uri, takeFlags); } selectedImagePath = FileUtils.getPath(this, uri); Log.i("path", "path: " + selectedImagePath); selectImageFile = new File(selectedImagePath); String error; StegoStructure adr[] = DD.getAvailableStegoStructureInstances(); int[] selected = new int[1]; try { error = DD.loadBMP(selectImageFile, adr, selected); Log.i("error", "error: " + error); if (error == "") { adr[selected[0]].save(); Toast.makeText(this, "add new safe other successfully!", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Toast.makeText(this, "Unable to load safe from this photo!", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } super.onActivityResult(requestCode, resultCode, resultData); }
From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java
/** * Share the videos selected//from www . j av a 2 s . c o m * * @param positions Integer ArrayList containing the positions of the videos to be shared * * @see #shareVideo(int postion) */ private void shareVideos(ArrayList<Integer> positions) { ArrayList<Uri> videoList = new ArrayList<>(); for (int position : positions) { videoList.add(FileProvider.getUriForFile(context, context.getPackageName() + ".provider", videos.get(position).getFile())); } Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType("video/*") .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .putParcelableArrayListExtra(Intent.EXTRA_STREAM, videoList); context.startActivity( Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title))); }
From source file:org.catrobat.paintroid.MainActivity.java
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.nav_back_to_pocket_code: showSecurityQuestionBeforeExit(); break;/*from w w w . ja v a2 s . com*/ case R.id.nav_export: PaintroidApplication.saveCopy = true; SaveTask saveExportTask = new SaveTask(this); saveExportTask.execute(); break; case R.id.nav_save_image: SaveTask saveTask = new SaveTask(this); saveTask.execute(); break; case R.id.nav_save_duplicate: PaintroidApplication.saveCopy = true; SaveTask saveCopyTask = new SaveTask(this); saveCopyTask.execute(); break; case R.id.nav_open_image: onLoadImage(); break; case R.id.nav_new_image: newImage(); break; case R.id.nav_fullscreen_mode: setFullScreen(true); break; case R.id.nav_exit_fullscreen_mode: setFullScreen(false); break; case R.id.nav_tos: DialogTermsOfUseAndService termsOfUseAndService = new DialogTermsOfUseAndService(); termsOfUseAndService.show(getSupportFragmentManager(), "termsofuseandservicedialogfragment"); break; case R.id.nav_help: Intent intent = new Intent(this, WelcomeActivity.class); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(intent); break; case R.id.nav_about: DialogAbout about = new DialogAbout(); about.show(getSupportFragmentManager(), "aboutdialogfragment"); break; case R.id.nav_lang: Intent language = new Intent(this, MultilingualActivity.class); startActivityForResult(language, REQUEST_CODE_LANGUAGE); break; } drawerLayout.closeDrawers(); return true; }
From source file:com.maskyn.fileeditorpro.activity.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { if (requestCode == SELECT_FILE_CODE) { final Uri data = intent.getData(); final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data), AccessStorageApi.getName(this, data)); newFileToOpen(newUri, ""); } else if (requestCode == SELECT_FOLDER_CODE) { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isFile(); }//from ww w . j a v a 2s . c om }; final Uri data = intent.getData(); File dir = new File(data.getPath()); File[] fileList = dir.listFiles(fileFilter); for (int i = 0; i < fileList.length; i++) { Uri particularUri = Uri.parse("file://" + fileList[i].getPath()); final GreatUri newUri = new GreatUri(particularUri, AccessStorageApi.getPath(this, particularUri), AccessStorageApi.getName(this, particularUri)); greatUris.add(newUri); refreshList(newUri, true, false); arrayAdapter.selectPosition(newUri); } if (fileList.length > 0) { Uri particularUri = Uri.parse("file://" + fileList[0].getPath()); final GreatUri newUri = new GreatUri(particularUri, AccessStorageApi.getPath(this, particularUri), AccessStorageApi.getName(this, particularUri)); newFileToOpen(newUri, ""); } } else { final Uri data = intent.getData(); final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data), AccessStorageApi.getName(this, data)); // grantUriPermission(getPackageName(), data, Intent.FLAG_GRANT_READ_URI_PERMISSION); final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. getContentResolver().takePersistableUriPermission(data, takeFlags); if (requestCode == READ_REQUEST_CODE || requestCode == CREATE_REQUEST_CODE) { newFileToOpen(newUri, ""); } if (requestCode == SAVE_AS_REQUEST_CODE) { new SaveFileTask(this, newUri, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding, new SaveFileTask.SaveFileInterface() { @Override public void fileSaved(Boolean success) { savedAFile(greatUri, false); newFileToOpen(newUri, ""); } }).execute(); } } } }
From source file:com.osama.cryptofm.filemanager.ui.FilemanagerTabs.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == GET_PERMISSION_CODE) { Uri treeUri = data.getData(); Log.d(TAG, "onActivityResult: tree uri is: " + treeUri); //save the uri for later use SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString("tree_uri", treeUri.toString()); editor.apply();/*from ww w . j ava2s.co m*/ editor.commit(); // Check for the freshest data. getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } }
From source file:com.groksolutions.grok.mobile.GrokActivity.java
/** * Share a screen capture via email or another provider *//*from w ww . jav a 2 s . com*/ private void shareScreenCapture() { Intent shareIntent = new Intent(Intent.ACTION_SEND); Uri uri = this.takeScreenCapture(true); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setData(uri); shareIntent.setType("image/jpeg"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.title_share))); }
From source file:com.bitants.wally.fragments.ImageZoomFragment.java
private void setImageAsWallpaperPicker(Uri fileUri) { Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.setType("image/*"); MimeTypeMap map = MimeTypeMap.getSingleton(); String mimeType = map.getMimeTypeFromExtension("png"); intent.setDataAndType(fileUri, mimeType); intent.putExtra("mimeType", mimeType); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, getString(R.string.action_set_as))); }