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.commonsware.android.videorecord.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_ID && resultCode == RESULT_OK) { Intent view = new Intent(Intent.ACTION_VIEW).setDataAndType(outputUri, "video/mp4") .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(view);//from ww w .ja v a 2 s . c o m finish(); } }
From source file:org.telegram.ui.Components.WallpaperUpdater.java
public void showAlert(final boolean fromTheme) { AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); CharSequence[] items;/*from ww w . j a va 2 s . co m*/ if (fromTheme) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("SelectColor", R.string.SelectColor), LocaleController.getString("Default", R.string.Default), LocaleController.getString("Cancel", R.string.Cancel) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile( parentActivity, BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } parentActivity.startActivityForResult(takePictureIntent, 10); } catch (Exception e) { FileLog.e(e); } } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); parentActivity.startActivityForResult(photoPickerIntent, 11); } else if (fromTheme) { if (i == 2) { delegate.needOpenColorPicker(); } else if (i == 3) { delegate.didSelectWallpaper(null, null); } } } catch (Exception e) { FileLog.e(e); } } }); builder.show(); }
From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java
public void shareLog(Activity activity) { File logPath = new File(activity.getBaseContext().getFilesDir(), LOG_FILE_NAME); Uri contentUri = FileProvider.getUriForFile(activity.getBaseContext(), "at.ac.tuwien.caa.fileprovider", logPath);/* w w w . j ava2 s. c o m*/ String emailSubject = activity.getBaseContext().getString(R.string.log_email_subject); String[] emailTo = new String[] { activity.getBaseContext().getString(R.string.log_email_to) }; String text = activity.getBaseContext().getString(R.string.log_email_text); Intent intent = ShareCompat.IntentBuilder.from(activity).setType("text/plain").setSubject(emailSubject) .setEmailTo(emailTo).setStream(contentUri).setText(text).getIntent() .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivity(intent); }
From source file:org.glucosio.android.tools.ReadingToCSV.java
public Uri createCSV(final ArrayList<GlucoseReading> readings, String um) { File file = new File(context.getFilesDir().getAbsolutePath(), "glucosio_exported_data.csv"); //Getting a file within the dir. try {/*from www .j av a 2s. c om*/ FileOutputStream fileOutputStream = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fileOutputStream); osw.append(context.getResources().getString(R.string.dialog_add_concentration)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_measured)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_date)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_time)); osw.append('\n'); FormatDateTime dateTool = new FormatDateTime(context); if ("mg/dL".equals(um)) { for (int i = 0; i < readings.size(); i++) { osw.append(readings.get(i).getReading() + "mg/dL"); osw.append(','); osw.append(readings.get(i).getReading_type() + ""); osw.append(','); osw.append(dateTool.convertRawDate(readings.get(i).getCreated() + "")); osw.append(','); osw.append(dateTool.convertRawTime(readings.get(i).getCreated() + "")); osw.append('\n'); } } else { GlucosioConverter converter = new GlucosioConverter(); for (int i = 0; i < readings.size(); i++) { osw.append(converter.glucoseToMmolL(readings.get(i).getReading()) + "mmol/L"); osw.append(','); osw.append(dateTool.convertRawDate(readings.get(i).getCreated() + "")); osw.append(','); osw.append(dateTool.convertRawTime(readings.get(i).getCreated() + "")); osw.append('\n'); } } osw.flush(); osw.close(); Log.i("Glucosio", "Done exporting readings"); } catch (Exception e) { e.printStackTrace(); } context.grantUriPermission(context.getPackageName(), Uri.parse(file.getAbsolutePath()), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); return FileProvider.getUriForFile(context, context.getPackageName() + ".provider.fileprovider", file.getAbsoluteFile()); }
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./*from w w w . j a v a2s. c o m*/ */ 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.//from ww w . j a v a 2s .co m */ 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.commonsware.android.camcon.CameraContentDemoActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CONTENT_REQUEST) { if (resultCode == RESULT_OK) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(outputUri, "image/jpeg"); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(i);//w ww.j a v a 2 s . co m finish(); } } }
From source file:com.android.shell.BugreportReceiver.java
/** * Build {@link Intent} that can be used to share the given bugreport. *///from w ww . jav a2 s . c o m private static Intent buildSendIntent(Context context, Uri bugreportUri, Uri screenshotUri) { final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("application/vnd.android.bugreport"); intent.putExtra(Intent.EXTRA_SUBJECT, bugreportUri.getLastPathSegment()); intent.putExtra(Intent.EXTRA_TEXT, SystemProperties.get("ro.build.description")); final ArrayList<Uri> attachments = Lists.newArrayList(bugreportUri, screenshotUri); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments); final Account sendToAccount = findSendToAccount(context); if (sendToAccount != null) { intent.putExtra(Intent.EXTRA_EMAIL, new String[] { sendToAccount.name }); } return intent; }
From source file:com.allen.mediautil.ImageTakerHelper.java
/** * ?/*from w w w.jav a2 s . c om*/ * <p> * onActivityResult()? */ public static void openCamera(Activity activity, String authority) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputPictureUri(activity.getApplicationContext(), authority)); activity.startActivityForResult(intent, REQUEST_CAMERA); }
From source file:com.xbm.android.matisse.internal.utils.MediaStoreCompat.java
public void dispatchCaptureIntent(Context context, int requestCode) { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (captureIntent.resolveActivity(context.getPackageManager()) != null) { File photoFile = null;//from w w w . j a v a2s . co m try { photoFile = createImageFile(); } catch (IOException e) { e.printStackTrace(); } if (photoFile != null) { mCurrentPhotoPath = photoFile.getAbsolutePath(); mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), mCaptureStrategy.authority, photoFile); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri); captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, mCurrentPhotoUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (mFragment != null) { mFragment.get().startActivityForResult(captureIntent, requestCode); } else { mContext.get().startActivityForResult(captureIntent, requestCode); } } } }