List of usage examples for android.support.v4.content FileProvider getUriForFile
public static Uri getUriForFile(Context context, String str, File file)
From source file:io.plaidapp.ui.ShareDribbbleImageTask.java
@Override protected void onPostExecute(File result) { if (result == null) { return;/*from w w w . ja va 2 s. co m*/ } // glide cache uses an unfriendly & extension-less name, // massage it based on the original String fileName = shot.images.best(); fileName = fileName.substring(fileName.lastIndexOf('/') + 1); File renamed = new File(result.getParent(), fileName); result.renameTo(renamed); Uri uri = FileProvider.getUriForFile(activity, BuildConfig.FILES_AUTHORITY, renamed); ShareCompat.IntentBuilder.from(activity).setText(getShareText()).setType(getImageMimeType(fileName)) .setSubject(shot.title).setStream(uri).startChooser(); }
From source file:de.spiritcroc.ownlog.FileHelper.java
public static Uri getFileShare(Context context, File shareFile) { return FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, shareFile); }
From source file:com.commonsware.android.camcon.CameraContentDemoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();//from w ww.j av a 2s . c o m } else { output.getParentFile().mkdirs(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); if (savedInstanceState == null) { i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } startActivityForResult(i, CONTENT_REQUEST); } }
From source file:com.commonsware.android.camcon.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();/* www.ja v a 2s . c o m*/ } else { output.getParentFile().mkdirs(); } Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } try { startActivityForResult(i, CONTENT_REQUEST); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.msg_no_camera, Toast.LENGTH_LONG).show(); finish(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } }
From source file:com.fuck_boilerplate.rx_paparazzo.interactors.TakePhoto.java
private Uri getUri() { Context context = targetUi.getContext(); File file = imageUtils.getPrivateFile(Constants.SHOOT_APPEND); String authority = context.getPackageName() + "." + Constants.FILE_PROVIDER; return FileProvider.getUriForFile(context, authority, file); }
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);/*w w w. j a v a 2s .c o m*/ }
From source file:info.schnatterer.logbackandroiddemo.OpenLogActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Get URIs for log files using android.support.v4.content.FileProvider */ final Intent openFile = new Intent(Intent.ACTION_VIEW); Uri uriForFile = FileProvider.getUriForFile(this, getString(R.string.authority_log_file_provider), Logs.findNewestLogFile(this)); openFile.setDataAndType(uriForFile, "text/plain"); openFile.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(openFile);//from w w w. j a v a2 s .c o m finish(); }
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 {/*from www. ja v a 2 s .co 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:org.stenerud.kscrash.KSCrashReportFilterEmail.java
@Override public void filterReports(List reports, CompletionCallback completionCallback) throws KSCrashReportFilteringFailedException { ArrayList<Uri> attachments = new ArrayList<>(); String authority = BuildConfig.APPLICATION_ID + ".provider"; for (Object report : reports) { attachments.add(FileProvider.getUriForFile(context, authority, (File) report)); }// w w w. java 2 s .com Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("*/*"); // TODO: Why does this fail? // intent.setData(Uri.parse("mailto:")); intent.putExtra(Intent.EXTRA_EMAIL, recipients.toArray()); intent.putExtra(Intent.EXTRA_SUBJECT, subject); // Workaround for framework bug ArrayList<String> text = new ArrayList<>(); text.add(message); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_STREAM, attachments); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } completionCallback.onCompletion(reports); }
From source file:net.nym.utilslibrary.utils.IntentUtils.java
public static void openFile(Context context, File file, String authority) { try {//from w w w. ja v a 2 s. com Intent intent = new Intent(Intent.ACTION_VIEW); Uri data; // 7.0 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // "cn.com.firstcare.mobile.aph.fileprovider"???authorities data = FileProvider.getUriForFile(context, authority, file); // ? intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { data = Uri.fromFile(file); } intent.setDataAndType(data, FileUtils.getMimeType(file)); Logger.e("getMimeType=%s", FileUtils.getMimeType(file)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); Toaster.toaster(context, "??app"); } }