跳到主要內容

發表文章

目前顯示的是 6月, 2020的文章

Error : android.os.FileUriExposedException

android.os.FileUriExposedException RootCause:從Android 7.0開始,一個應用提供自身檔案給其它應用使用時,如果給出一個file://格式的URI的話,應用會丟擲FileUriExposedException。這是由於谷歌認為目標app可能不具有檔案許可權,會造成潛在的問題。 Solution: 使用FileProvider code java Uri uri=FileProvider. getUriForFile (context , context . getApplicationContext (). getPackageName () , imgFile) ; // Uri uri = Uri.fromFile(imgFile); or FileProvider. getUriForFile (context , context . getApplicationContext (). getPackageName () , mCsvFile ) android mainfest <provider android :name ="android.support.v4.content.FileProvider" android :authorities ="PackageName.fileprovider" android :exported ="false" android :grantUriPermissions ="true" > <meta-data android :name ="android.support.FILE_PROVIDER_PATHS" android :resource ="@xml/file_paths" /> </provider> add xml file  file name   file_paths