2017-03-02 88 views
0

我得到︰android.os.FileUriExposedException。相机不适用于安卓7.0

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); 

和onActivityResult

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

Please add sample code...if Available.

+0

有你请求在r处使用相机的许可不定时? – magicleon

+1

https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed https://github.com/commonsguy/cw-omnibus/tree/master/相机/ FileProvider https://github.com/commonsguy/cw-omnibus/tree/master/Media/VideoRecordIntent – CommonsWare

+0

是我已经添加了运行时权限....只针对Android N给android.os.FileUriExposedException ... –

回答

1

经过一番研究终于得到相关回答我的问题只是设定分钟目标SDK版本至23