Android Question Error opening PDF file

PHB2

Member
Licensed User
Longtime User
My app creates a PDF, which I would then like the app to open automatically, in whatever app is set to show PDF files

Having tried various approaches, the one problem I keep coming up with is the following error:

android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.fitnessmembership/files/220618/Form2020220161132.pdf exposed beyond app through Intent.getData()

I have changed my app to use both File.DirInternal and File.DirDefaultExternal in the thought it was a visibility issue, but I get the same error.

My code is:

B4X:
Dim In As Intent
Dim uri As String
uri = "file://" & File.Combine(WorkingPath, FormFileName )

In.Initialize(In.ACTION_VIEW, uri)
In.SetType("application/pdf")
In.SetComponent("com.adobe.reader/.AdobeReader")
'In.SetComponent("android/com.android.internal.app.ResolverActivity")
'In.WrapAsIntentChooser("Choose PDF Viewer")     
StartActivity(In)

I have tried (as you can see) forcing it to use Adobe, which I have installed, or also presenting the user with the app resolver screen to choose.

My code, having checked the forums, seems consistent with what others have written.

My question is whether I need to add to the Manifest file to support the execution of my Intent, and if so, some suggested code to get me going again.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top