Android Question How to check if Google Maps is install

makis_best

Active Member
Licensed User
Hi....

Is there any way I can check if Google Maps is installed and if it not then
ask for installation?

Thank you
 

Syd Wright

Well-Known Member
Licensed User
Hi....

Is there any way I can check if Google Maps is installed and if it not then
ask for installation?

Thank you
Check whether the Google Maps Package name exists on the device. If I am not mistaken it is: "com.google.android.gms.maps" (or "com.google.android.apps.maps").
You can use:
B4X:
Sub CHECK_PACKAGE1(Pack1 As String) As Int
    Dim PackList1 As List
    Dim Dhulp1 As String
    Dim pm As PackageManager
    PackList1 = pm.GetInstalledPackages
    For r=0 To PackList1.Size-1
      Dhulp1 = PackList1.GET(r)
      If Dhulp1.ToLowerCase = Pack1.ToLowerCase Then Return 1
    Next
    Return 0
End Sub
 

Syd Wright

Well-Known Member
Licensed User
Try this:
B4X:
Sub Process_Globals
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim Bitmap1 As Bitmap
    Dim Res As Int
    Dim Intent1 As Intent
    If CHECK_PACKAGE1("com.google.android.apps.maps")=0 Then
      Bitmap1.Initialize(File.DirAssets,"gmap1.jpg")     'You will have to add gmap1.jpg (attached below) to DirAssets
      Res=Msgbox2("Do you wish to install Google Maps?","Google Maps is not yet installed","YES","","NO",Bitmap1)
      If Res = DialogResponse.POSITIVE Then
        Intent1.Initialize(Intent1.ACTION_VIEW,"https://play.google.com/store/apps/details?id=com.google.android.apps.maps")
        StartActivity(Intent1)
      End If
    End If
End Sub

Sub CHECK_PACKAGE1(Pack1 As String) As Int
    Dim PackList1 As List
    Dim Dhulp1 As String
    Dim pm As PackageManager            'You need to add the Phone library
    PackList1 = pm.GetInstalledPackages
    For r=0 To PackList1.Size-1
      Dhulp1 = PackList1.GET(r)
      If Dhulp1.ToLowerCase = Pack1.ToLowerCase Then Return 1
    Next
    Return 0
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
You can omit the messagebox and go straight to the Playstore, but your users probably won't understand why.
 

Attachments

Last edited:
Top