跳到主要內容

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
<?xml version="1.0" encoding="utf-8"?><resources>    <paths>        <root-path name="root" path=""/>        <files-path name="files" path=""/>        <files-path name="Pictures" path="Pictures"/>        <cache-path name="cache" path=""/>        <external-path name="external" path=""/>        <external-files-path name="external_file_path" path=""/>        <external-cache-path name="external_cache_path" path=""/>    </paths></resources>




留言

這個網誌中的熱門文章

IOS Swift 在某路徑下產生檔案 txt json

語法:         func createFile(name: String , fileBaseUrl: URL ){             let manager = FileManager . default                          let file = fileBaseUrl. appendingPathComponent (name)             print ( "文件: \ ( file )" )             let exist = manager. fileExists (atPath: file. path )             if !exist {                 let data = Data (base64Encoded: "aGVsbG8gd29ybGQ=" ,options:. ignoreUnknownCharacters )                 let createSuccess = manager. createFile (atPath: file. path ,contents:data,attributes: nil )                 print ( "文件產生结果: \ ( createSuccess )" )             } ...

android eclipse transformation to android studio Error AAPT: error: style attribute 'attr/@attr/colorChecked (aka com.xxxxx:attr/@attr/colorChecked)' not found.

AAPT: error: style attribute 'attr/@attr/colorChecked 刪除 " @attr/" 即可!!