Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native display PDF in Android web view

I have a React Native app in which at some page I've got a web view (react-native-webview) for displaying PDFs from our server.

In iOS everything works fine, in Android, whenever I try to view the file I got:

Cannot downoad files as permission was denined. Please provide permission to write to storage, in order to download files.

I've then added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to my manifest. Now, I'm getting the following alert:

enter image description here

I think it's pretty scary and very stupid from a user experience perspective. I'm not accessing photos, media, or files, all I'm trying to do is to display a simple PDF inside a web view. I don't want my users to be presented such alert.

When I tap allow, it says Downloading... and downloads the PDF like a file that can be opened outside my app. I don't want this behavior, I want PDF to render inside web view just like iOS does.

How can I display PDFs in Android using React Native web view, without a scary dialog which has nothing to do with what I'm actually trying to do?

(I'm on React Native 0.59.9, Android 8.1, Android SDK 28, react-native-web-view 5.12.0)

like image 207
Can Poyrazoğlu Avatar asked Oct 15 '22 13:10

Can Poyrazoğlu


1 Answers

After trying various things I've given up on displaying PDFs directly and converting it to HTML. There's apparently no reliable way to display PDFs in default browser (viewing PDF directly might work on some machines but definitely not reliable as it didn't on my device/emulators).

like image 82
Can Poyrazoğlu Avatar answered Oct 19 '22 00:10

Can Poyrazoğlu