react-native-file-viewer icon indicating copy to clipboard operation
react-native-file-viewer copied to clipboard

Unable to open file in Android

Open moonfoan opened this issue 3 weeks ago • 0 comments

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?

moonfoan avatar Feb 08 '25 00:02 moonfoan