I've developed a simple app that creates a PDF file which is then saved to a folder.
The app then allows the user to view the PDF using the following intent-
dim xintent as intent
Dim zpathfile As String
zpathfile="file://" & PDFfolder & "/" & "pdf1.pdf"
xintent.Initialize(xintent.ACTION_VIEW,zpathfile)
xintent.SetType("application/pdf")
xintent.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(xintent)
It works fine on my Android 5.1.1 tablet and on my Android 6.0 phone.
My friend also wants to use the app but there's a problem when he runs it on his Android 9.0 phone.
The PDF file is created and stored okay but the app crashes when he tries to view the PDF file.
I've looked at trying to use Filepicker, Fileprovider and think there must be some issue with runtime permissions.
I'm totally lost!
The app is for our use only and will not need to conform to Google Play requirements.
Could someone please point me in the right direction so the app will work on the Android 9.0 device?
Especially you need to use FileProvider to share a file with another app.
This code snippet may help you (note to implement FileProvider correctly first).
B4X:
Dim FileName As String = "xx.pdf"
File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
Starter.Provider.SetFileUriAsIntentData(in, FileName)
'Type must be set after calling SetFileUriAsIntentData
in.SetComponent("android/com.android.internal.app.ResolverActivity")
in.SetType("application/pdf")
StartActivity(in)