无法找到包含/ data / data / [FileProvider]的已配置根目录

时间:2016-01-12 15:10:59

标签: android uri android-fileprovider

我是Android的新手,现在我已经坚持生成内容Uri。 我已经从listView中显示了目录中的所有文件 我试图在用户点击指定项目时使用FileProvider.getUriForFile()生成内容Uri

 public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId) {

     mPrivateRootDir = getFilesDir();
     mDocumentDir = new File(mPrivateRootDir,"Download");
     mDocumentFile = mDocumentDir.listFiles(); //get file in directory file[]
     mDocumentFileNames = mDocumentDir.list() //get file name String[]
     File requestedFile = new File(mDocumentDir, mDocumentFileNames[position]);
 try {
      fileUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.gunawan.sharedprovider.fileprovider", requestedFile);
      } catch (IllegalArgumentException e) {
      Log.e("File Selector", e.getMessage());
      }
    }

我的FileInvider in Manifest

<provider
   android:name="android.support.v4.content.FileProvider"
   android:authorities="com.example.gunawan.sharedprovider.fileprovider"
   android:exported="false"
   android:grantUriPermissions="true">
   <meta-data
     android:name="android.support.FILE_PROVIDER_PATHS"
     android:resource="@xml/filepaths"/>
</provider>

文件路径XML

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <file-path path="Download/" name="download" />
</paths>

当我点击文件

时,它总是显示如下
01-12 21:47:52.504 24955-24955/com.example.gunawan.sharedprovider E/File Selector: Failed to find configured root that contains /data/data/com.example.gunawan.sharedprovider/files/Download/0file.txt
01-12 21:47:53.824 24955-24955/com.example.gunawan.sharedprovider E/File Selector: Failed to find configured root that contains /data/data/com.example.gunawan.sharedprovider/files/Download/3file.txt

autorities有问题吗?

0 个答案:

没有答案