Skip to content

Unable to open file in Android #166

@moonfoan

Description

@moonfoan

I'm trying to open a pdf document with FileView.open(filePath) and the filePath is like /data/user/0/com.myapp.dev/attachments/Copies/my_doc.pdf (in Android)

The codes work perfectly fine in iOS, but it is failing in Android and throwing the following error:
Failed to find configured root that contains /data/data/com.myapp.dev/attachments/Copies/my_doc.pdf.
It is failing in this particular line in the RNFileViewerModule.java file from my bebugging:
contentUri = FileProvider.getUriForFile(currentActivity, authority, newFile);

Here's some additional infomation:

  • I have verified that the original file path exists, and I can open it in webview just fine.
  • I have granted WRITE_EXTERNAL_STORAGE permission to my app
  • App is on React Native 0.76.6
  • Testing on Android 11
  • I have added thequeries tag in the AndroidManifest.xml as suggested in the documentation:
<manifest ...>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <data android:mimeType="*/*"/>
    </intent>
  </queries>
  <application...>
     ........
  </application>
</manifest>

I have no idea why it is looking into /data/data/ directory instead of the given /data/user/ directory. Any suggestion to resolve this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions