1

I'm getting: android.os.FileUriExposedException.

When targeting Android N, file:// URIs are not allowed anymore. I know We should use content:// URIs instead. However, my app needs file for both image and video. Any ideas?

  mMediaUri = Uri.fromFile(new File(AppHelper.getDirectoryPath(),AppHelper.getFileName() + ".jpeg"));

  Intent iCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  iCamera.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
  startActivityForResult(iCamera, Constants.INTENT_CALL.CAPTURE_IMAGE);

and onActivityResult

case Constants.INTENT_CALL.CAPTURE_IMAGE:
String filePath=SiliCompressor.with(getActivity()).compress(mMediaUri.toString(), true);

Please add sample code...if Available.

yogeshwar nair
  • 793
  • 2
  • 5
  • 21
  • have you requested the permission for using camera at runtime? – magicleon94 Mar 02 '17 at 17:29
  • 1
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed https://github.com/commonsguy/cw-omnibus/tree/master/Camera/FileProvider https://github.com/commonsguy/cw-omnibus/tree/master/Media/VideoRecordIntent – CommonsWare Mar 02 '17 at 17:32
  • yes I have added the run time permission.... only targeting Android N gives android.os.FileUriExposedException.... – yogeshwar nair Mar 02 '17 at 18:10
  • Yes you should use a FileProvider. You are number #### who encounters this problem. Code has been published many times here. Your app needs a file? But the Camera app you use is happy with a content scheme. – greenapps Mar 02 '17 at 18:17
  • @greenapps here I am getting error:String filePath=SiliCompressor.with(getActivity()).compress(mMediaUri.toString(), true); do you know how to resolve it. – yogeshwar nair Mar 05 '17 at 20:22
  • O are you getting an error? And you are not telling what error exactly? What do you have in mind? And why not post complete onActivityResult code? – greenapps Mar 05 '17 at 20:34
  • @greenapps i got solution and error occurred because of sillicompressor as its take input as file not content... – yogeshwar nair Mar 16 '17 at 19:20

1 Answers1

4

After some research finally got relevant answer to my question just set min target sdk version to 23.

yogeshwar nair
  • 793
  • 2
  • 5
  • 21