2017-03-02 60 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