1

我是 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());
      }
    }

我在清单中的 FileProvider

<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

当局有什么问题吗?

4

0 回答 0