Android Question Check if pdf document can be opened

Juan Vargas (Bioagro)

Member
Licensed User
I have this piece of code

B4X:
      ' open Pdf Document
            Try
                Dim in As Intent
                in.Initialize(in.ACTION_VIEW, "")
                Starter.Provider.SetFileUriAsIntentData(in, PdfFile)
                in.SetType("application/pdf")
                StartActivity(in)
            Catch
                MsgboxAsync("It seems that there's not a Pdf viewer application in the device", "Open Document")
                Wait For Msgbox_Result (Resultx As Int)
            End Try

The thing is that the 'catch' segment does not execute, Android (Api 29) send a fast dissapear toast message "Please Install or Update the Addon Pdf".
For users like me that's no problem. But I'd like to take control and send a better message like, "Please Install Acrobat Reader" or something.
Is there any way to do that?
 

JohnC

Expert
Licensed User
Longtime User
This thread may be of help:

 
Upvote 0

Juan Vargas (Bioagro)

Member
Licensed User
I used this code following your answer

B4X:
            Dim pm As PackageManager
            Dim Intent1 As Intent
            Intent1.Initialize(Intent1.ACTION_VIEW, "file://")
            Intent1.SetType("application/pdf")
            For Each cn As String In pm.queryIntentActivities (Intent1)
                Log(cn)
            Next

And it returns one item: com.mixplorer/.activities.EBookReaderActivity

Its no use. No application is opened. Better if nothing is found.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
If that ebookreader app doesn't handle PDF files, then my only guess is that you might need to tweak the intent a little more, or perform multiple tests with different intents and come up with some type of multi-step test to see if there are any apps that can properly open PDF files or not.

There is also this solution:

 
Upvote 0

Juan Vargas (Bioagro)

Member
Licensed User
Thanks.
Tried the sample, in B4A for this line in the link you sent
B4X:
if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0)

Like this
B4X:
            For Each cn As String In pm.queryIntentActivities (Intent1, pm.MATCH_DEFAULT_ONLY)
                Log(cn)
            Next

But B4A does not allow more than one parameter in the function queryIntentActivities
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The thing is that the 'catch' segment does not execute, Android (Api 29) send a fast dissapear toast message "Please Install or Update the Addon Pdf".
This message comes from this app: com.mixplorer/.activities.EBookReaderActivity
You cannot catch this error as there is no error. This app is registered to handle PDF files. Whether it can actually handle them or not is a different question.
 
Upvote 0
Top