Android Question [Solved]Check if Gmail App is Installed

73Challenger

Active Member
Licensed User
Is there a way to check if the gmail app is installed on an android device?
My app calls out to the gmail app using this code.
Gmail Snippit:
    intent1 = msg.GetIntent
    If sdk >= 23 Then
        intent1.SetComponent("com.google.android.gm/.ComposeActivityGmailExternal")
    Else
        intent1.SetComponent("com.google.android.gm/.ComposeActivityGmail")
    End If

I'd like to check to see if it's installed and prompt the user if it's not there.
Apologies if the question has already been answered. I searched and didn't see a relevant thread.
Thanks much!
 

73Challenger

Active Member
Licensed User
Found the answer by using Package Manager as a search term. This is the thread describing the process. Thank you.
https://www.b4x.com/android/forum/threads/packagemanager-dont-find-whatsapp.131527/

Not much new in the code below, I just wanted to document it in case someone finds this thread in the future.

Check if Gmail app is installed:
'1. Add a new app manifest queries section
AddManifestText(<queries>
<package android:name="com.google.android.gm"/>
</queries>)

'2. Method Function
Private Sub isPackageInstalled(packageName As String) As Boolean
    Dim Intent1 As Intent
    Dim pm As PackageManager
    Intent1 = pm.GetApplicationIntent(packageName)
    Return Intent1.IsInitialized
End Sub

'3. Calling Sub
Private Sub btnEmail_Click
    If isPackageInstalled("com.google.android.gm") = False Then
        ToastMessageShow("GMAIL App is required to send emails.", True)
    Else
        ToastMessageShow("Gmail Installed", True)
    End If
    Email.Email_Result
End Sub
 
Last edited:
Upvote 0
Top