Android Question [SOLVED] Alternative to check if WhatsApp is installed without using PackageManager - QUERY_ALL_PACKAGES on + SDK30

scsjc

Well-Known Member
Licensed User
Longtime User
Until now I used PackageManager to check which applications were installed (for example WhatsApp)

Currently google requires QUERY_ALL_PACKAGES in Manifest in order to have a list of Installed Packages.

Is it possible to know if WhatsApp is installed, via tried through some kind of Try-Catch error?




B4X:
Sub APKinstalada(packagename As String) As Boolean
    Try
        Dim PM As PackageManager   
        Dim ApplicationLabel As String = PM.GetApplicationLabel(packagename)
        log("Installed: " & ApplicationLabel)
        Return True
    Catch
        log("Not Installed: " & packagename)
        Return False
    End Try
End Sub

B4X:
 Dim pm As PackageManager
    Dim in As Intent
    in = pm.GetApplicationIntent("com.somewhat.package")
    If in.IsInitialized Then
        ' Package is installed
    End If
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
I find solution, add manifest:

B4X:
AddManifestText(<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I don't know if this will help but this is how I try to open Edge
B4X:
        If ext = ".htm" Or ext = ".html" Then
            ' Provider needs manifest AddApplicationText entry for FileProvider
            ' Provider needs manifest CreateResource entry for File.DirRootExternal
            Provider.SharedFolder = File.DirRootExternal
            helpintent.Initialize(helpintent.ACTION_VIEW, Provider.GetFileUri(helpfile))
            helpintent.SetType("text/html")
            helpintent.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
            helpintent.SetPackage("com.microsoft.emmx")
            Try
                StartActivity(helpintent)
            Catch
                MsgboxAsync("An installation of Microsoft Edge is required to read this help file.", "Microsoft Edge")
            End Try
            Return
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
I don't know if this will help but this is how I try to open Edge
B4X:
        If ext = ".htm" Or ext = ".html" Then
            ' Provider needs manifest AddApplicationText entry for FileProvider
            ' Provider needs manifest CreateResource entry for File.DirRootExternal
            Provider.SharedFolder = File.DirRootExternal
            helpintent.Initialize(helpintent.ACTION_VIEW, Provider.GetFileUri(helpfile))
            helpintent.SetType("text/html")
            helpintent.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
            helpintent.SetPackage("com.microsoft.emmx")
            Try
                StartActivity(helpintent)
            Catch
                MsgboxAsync("An installation of Microsoft Edge is required to read this help file.", "Microsoft Edge")
            End Try
            Return

I had already thought about launching directly and sharing to whatsapp, and that TryCatch would check if it works, and if not give an error

But I would like to be able to show the WhatsApp button if it is installed, and if it is not installed hide the button. (Same for WhatsAppBussines)
 
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
I had already thought about launching directly and sharing to whatsapp, and that TryCatch would check if it works, and if not give an error

But I would like to be able to show the WhatsApp button if it is installed, and if it is not installed hide the button. (Same for WhatsAppBussines)
No need to add QUERY_ALL, just add the com.whatsapp to your manifest:
<queries> <!-- Explicit apps you know in advance about: --> <package android:name="com.whatsapp"/> <package android:name="com.whatsapp.w4b"/> </queries>
 
Upvote 0
Top