Search code examples
androidreact-nativewebviewreact-native-webview

react-native-webview on Android cannot load a local file saved on the cache directory with the ERR_ACCESS_DENIED


In my app, I download and save a file to my app's cache directory (e.g. file:///data/user/0/.../cache/5f8f.../downloaded.pdf) and try to open this file using WebView. My WebView code is:

<WebView
  source={{ uri: file.uri }}
  startInLoadingState
  originWhitelist={['file://']}
  allowUniversalAccessFromFileURLs={true}
  allowFileAccess={true}
/>

On iOS, it works fine. However, on Android, it prints ERR_ACCESS_DENIED.

I've tried some solutions found on GitHub and StackOverflow:

, but still not working on my case.

Any other solution to solve my problem? Thanks, in advance. If you need more code to investigate, please let me know.

== edit: file.uri looks like file:///data/user/0/.../cache/5f8f.../downloaded.pdf. It is a file stored on the cache directory.


Solution

  • A Webview on Android cannot display a pdf document.