1

私はアンドロイドが初めてで、コンテンツ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