Android Question Check version and/or presense of Google Play Services + help install update

JohnC

Expert
Licensed User
Longtime User
This is a question related to this thread: https://www.b4x.com/android/forum/threads/check-and-install-google-play-services.84813/

I just ran my app on an android 4.4.4 and this routine popped up the "You need an update" and returned false.

However, I ignored installing the update and the two libraries (Firebase CrashLytic and Google Analytics) that I was doing this check for worked just fine (I forced a fault) without the play services update.

It appears these libraries don't need the latest version of PS to work OK.

So, it there anyway to modify this routine to report the version of the play services? I ask because I don't want to bother the user to do an update when it may not even be needed.

Worse case, is there a way to see if PS is installed at all? And if not, is "com.google.android.gms" the proper package name to jump the user to the playstore to install it if its not present?
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Something like this perhaps ?

B4X:
Sub CheckForGooglePlayServices As Boolean
    Log("Checking for Play Services")
    Dim GoogleApiAvailablity As JavaObject
    GoogleApiAvailablity = GoogleApiAvailablity.InitializeStatic("com.google.android.gms.common.GoogleApiAvailability").RunMethod("getInstance", Null)
    Dim context As JavaObject
    context.InitializeContext
    If GoogleApiAvailablity.RunMethod("isGooglePlayServicesAvailable", Array(context)) <> 0 Then
        GoogleApiAvailablity.RunMethod("makeGooglePlayServicesAvailable", Array(context))
        Return False
    End If
    Return True
End Sub
Source: - This Forum (somewhere)

I usually use it right after I have checked my permissions, and then make sure that you have the latest version downloaded by using your SDK Manager and do a simple search "PlayServices" near the top of your SDK manager screen and it will show you if you need to update.

Enjoy !!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Your code seems to be almost identical to Erel's (that I mentioned in my OP) in that it checks to see if the user's play services is the "latest" version - not if PS exists at all or not on the users device.

As I mentioned in my OP, Firebase and Analytics seems to work fine even if the user doesn't have the latest version of PS.

So to prevent me from bothering the user unnecessarily, I just want to see if ANY version of PS exists (not if it's the latest or not). This way if any version exists on the users device, I can pretty safely assume that firebase and analytics will run ok and there is no need to bother the user with doing an upgrade of "some" app that may be suspicious to them because they have no idea what "google play services" is.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hi Erel,

You by far know the inside of android magnitudes better then I do. So, when you make a statement I consider it to be fact.

So when in this thread (https://www.b4x.com/android/forum/threads/google-play-services-where-is-it.94743/#post-599297) you said "will probably work", I took as you were not 100% sure. And you also say "my guess is that..." in this thread.

So, I am just playing it safe so I don't assume something incorrectly and then get a bunch of negative reviews because my app crashes for some users.

With regard to testing these situations with the emulator. Am I wrong to assume that the emulator images will already have GPS installed on them, and if so, I have no idea how to remove them from the emulator to see if it will cause firebase to not work.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK this is where my lack of android will cause a problem because I don't know exactly how to "choose a google_apis platform". But I understand it is probably common sense to you because of your experience.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Are you talking about the "images" of the emulator and if use an image that doesnt say "google" in it's title, then that means it wont have the play services in it?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Well, I can confirm that both Google Analytics AND Firebase "Crashlytics" do NOT need Play Services to operate properly because they both report a crash on a non-google api 24 platform :)

That's Erel for helping me determine this for sure.
 
Upvote 0
Top