I am using PDF.js to show PDF files inside my Android App. Up to Android 10 it worked fine, but starting with "targetSdkVersion 30" it doesn't work anymore.
If I want to open and show a PDF file, PDF.js shows
Missing PDF "file:///storage/emulated/0/Android/data/<App-ID>/files/file.pdf
The path ist definitely correct, I checked it and generated it with getExternalFilesDir(null).absolutePath
The whole URL to load is
file:///android_asset/web/viewer.html?file=/storage/emulated/0/Android/data/<app-ID>/files/file.pdf
Using "targetSdkVersion 29" and changing nothing else, all works fine, so it seems "targetSdkVersion 30" causes somehow the problem.
To fix a PDF file not opening in Adobe reader, you will need to download the latest version of Adobe Reader. After which you will disable the protected mode that comes with it by default. Once this is changed, the issue of the PDF file not opening in Adobe reader will be resolved.
js by Manuel Reimer. Opens PDF files on Firefox for Android using PDF. js.
To launch an Intent on a PDF file, the mobile device should have installed a program that can read PDF documents. If you do not want the user to have a PDF reader's installed, you must modify your application to be able to read PDF documents. Show activity on this post. you need to install apk in emulator.
Why can't I open PDF files on my Android phone? If you can't view PDF documents on your device, check if the file is corrupted or encrypted. If that isn't the case, use different reader apps, and see which one works for you.
The solution was pretty simple (shame on me):
Up to API 29 I only used:
webView.settings.allowFileAccessFromFileURLs = true
Since API 30 I have to use:
webView.settings.allowFileAccessFromFileURLs = true
webView.settings.allowFileAccess = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With