List of usage examples for android.support.v4.content FileProvider getUriForFile
public static Uri getUriForFile(Context context, String str, File file)
From source file:com.iceteck.silicompressorr.FileUtils.java
/** * Convert File into Uri.// www. jav a2 s.co m * * @param file * @return uri */ public static Uri getUri(Context context, File file) { if (file != null) { return FileProvider.getUriForFile(context, SiliCompressor.getAuthorities(context), file); //Uri.fromFile(file); } return null; }
From source file:com.github.vase4kin.teamcityapp.artifact.router.ArtifactRouterImpl.java
/** * {@inheritDoc}// w w w . j a va2s . co m */ @Override public void startFileActivity(File file) { MimeTypeMap map = MimeTypeMap.getSingleton(); String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName()); String type = map.getMimeTypeFromExtension(ext); if (type == null) { type = ALL_FILES_TYPE; } Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = FileProvider.getUriForFile(mActivity, BuildConfig.APPLICATION_ID + ".provider", file); intent.setDataAndType(data, type); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); //User couldn't have app with type intent try { mActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException e) { intent.setDataAndType(data, ALL_FILES_TYPE); mActivity.startActivity(intent); } }
From source file:com.android.shell.BugreportReceiver.java
@Override public void onReceive(Context context, Intent intent) { final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT); final File screenshotFile = getFileExtra(intent, EXTRA_SCREENSHOT); // Files are kept on private storage, so turn into Uris that we can // grant temporary permissions for. final Uri bugreportUri = FileProvider.getUriForFile(context, AUTHORITY, bugreportFile); final Uri screenshotUri = FileProvider.getUriForFile(context, AUTHORITY, screenshotFile); Intent sendIntent = buildSendIntent(context, bugreportUri, screenshotUri); Intent notifIntent;//from w ww. j a va 2 s . co m // Send through warning dialog by default if (getWarningState(context, STATE_SHOW) == STATE_SHOW) { notifIntent = buildWarningIntent(context, sendIntent); } else { notifIntent = sendIntent; } notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(com.android.internal.R.drawable.stat_sys_adb); builder.setContentTitle(context.getString(R.string.bugreport_finished_title)); builder.setTicker(context.getString(R.string.bugreport_finished_title)); builder.setContentText(context.getString(R.string.bugreport_finished_text)); builder.setContentIntent( PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.setAutoCancel(true); NotificationManager.from(context).notify(TAG, 0, builder.build()); // Clean up older bugreports in background final PendingResult result = goAsync(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { FileUtils.deleteOlderFiles(bugreportFile.getParentFile(), MIN_KEEP_COUNT, MIN_KEEP_AGE); result.finish(); return null; } }.execute(); }
From source file:net.bluehack.ui.Components.AvatarUpdater.java
public void openCamera() { try {/*from ww w .j a va 2s .c o m*/ 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( parentFragment.getParentActivity(), 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(); } parentFragment.startActivityForResult(takePictureIntent, 13); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:kr.wdream.ui.Components.AvatarUpdater.java
public void openCamera() { try {//w ww . jav a 2 s.c o m Log.d("AvatarUpdater", "openCamera"); 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( parentFragment.getParentActivity(), 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(); } parentFragment.startActivityForResult(takePictureIntent, 13); } catch (Exception e) { FileLog.e("tmessages", e); } }
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 w ww. j a v a 2 s .c om*/ } } 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.silentcircle.contacts.utils.ContactPhotoUtils19.java
/** * Generate a new, unique file to be used as an out-of-band communication * channel, since hi-res Bitmaps are too big to serialize into a Bundle. * This file will be passed to other activities (such as the gallery/camera/cropper/etc.), * and read by us once they are finished writing it. *//*from w w w . j a va2s .c o m*/ public static Uri generateTempImageUri(Context context) { return FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, new File(pathForTempPhoto(context, generateTempPhotoFileName()))); }
From source file:com.android.settings.SettingsLicenseActivity.java
@VisibleForTesting
Uri getUriFromGeneratedHtmlFile(File generatedHtmlFile) {
return FileProvider.getUriForFile(this, RestrictedProfileSettings.FILE_PROVIDER_AUTHORITY,
generatedHtmlFile);
}
From source file:eu.geopaparazzi.library.util.Utilities.java
public static Uri getFileUriInApplicationFolder(Context context, File imageFile) throws Exception { String packageName = ResourcesManager.getInstance(context).getPackageName(); Uri outputFileUri = FileProvider.getUriForFile(context, packageName + GEOPAPARAZZI_LIBRARY_FILEPROVIDER_PLUS, imageFile); return outputFileUri; }
From source file:com.hbm.devices.scan.ui.android.DeviceZipper.java
static Uri saveAnnounces(@NonNull List<Announce> announces, @NonNull AppCompatActivity activity) { final TimeZone tz = TimeZone.getTimeZone("UTC"); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US); df.setTimeZone(tz);/*from w w w . ja v a2 s .c o m*/ final String isoDate = df.format(new Date()); final Charset charSet = Charset.forName("UTF-8"); try { final File file = createFile(activity); if (file == null) { return null; } final FileOutputStream fos = new FileOutputStream(file, false); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); final ZipEntry entry = new ZipEntry("devices.json"); zos.putNextEntry(entry); zos.write(("{\"date\":\"" + isoDate + "\",").getBytes(charSet)); zos.write(("\"version\": \"1.0\",").getBytes(charSet)); zos.write("\"devices\":[".getBytes(charSet)); final Iterator<Announce> iterator = announces.iterator(); while (iterator.hasNext()) { final Announce announce = iterator.next(); zos.write(announce.getJSONString().getBytes(charSet)); if (iterator.hasNext()) { zos.write(",\n".getBytes(charSet)); } } zos.write("]}".getBytes(charSet)); zos.closeEntry(); zos.close(); fos.close(); return FileProvider.getUriForFile(activity, "com.hbm.devices.scan.ui.android.fileprovider", file); } catch (IOException e) { Toast.makeText(activity, activity.getString(R.string.could_not_create, e), Toast.LENGTH_SHORT).show(); return null; } }