React Native display PDF in Android web view

Can*_*ğlu 5 android android-permissions react-native react-native-android react-native-webview

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:

在此处输入图片说明

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)

Can*_*ğlu 4

在尝试了各种方法之后,我放弃了直接显示 PDF 并将其转换为 HTML。显然没有可靠的方法在默认浏览器中显示 PDF(直接查看 PDF可能在某些机器上可以工作,但绝对不可靠,因为它在我的设备/模拟器上不可靠)。