Android Question Google Play Services

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All

I am having difficulties bundling the latest version of Google Play Services with the apk.

Background:
  • Currently I am using B4A 7.01
  • Android SDK shows Google Play Services ver 44
  • I cant find libproject folder under google_play_services folder. so I can't find the latest .jar file to move to my additional libraries folder ( i am not sure if this
  • When I install my apk on a tablet with older version of Google Play Services the app is not working properly. Also I find that the google-play-services version running on the tablet is unchanged with the installation (meaning running an older one)
  • I have the following 2 lines added in the project
    B4X:
        #AdditionalJar: com.google.android.gms:play-services-location
        #AdditionalJar: com.google.android.gms:play-services-maps
  • And this is what I have in the manifest
    B4X:
    '************ Google Play Services Base ************
    AddApplicationText(
       <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      android:exported="false"/>
        <meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
    <meta-data android:name="com.google.android.geo.API_KEY"
    android:value="AIxxxxxxxxxxxxxxxxxxxxxxxxxxxA"/> 
    )
    '************ Google Play Services Base (end) ************

Is there a step by step tutorial how to make sure that we bundle the latest Google-Play-Services with the apk.
 

tigrot

Well-Known Member
Licensed User
Longtime User
My Manifest.
B4X:
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
)
add the line AddManifestText to your code.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
My Manifest.
B4X:
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
)
add the line AddManifestText to your code.

Hi Tigort

Thanks for your input, but I already have all of the above in the manifest file. I just didn't show that line my first post.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
it is not needed anymore using the new maven repositories.

Use this tool to install all needed things.
https://www.b4x.com/android/forum/threads/gui-sdk-manager-for-newer-versions-of-android-tools.80090/
Make sure to update the path in file configure paths to the new android.jar

Hi Don,
thanks for your reply.
I did try the above but I am still facing the same issue

Something still not right. Here is what I am doing:
  • I wipe my devices (Factory Reset)
  • I check Google Play Services version # ( 8.xx & 9.xx)
  • Email my apk to the devices
  • I install my apk
  • I check Google Play Services version #, it seems to be unchanged
  • I run the app, it starts misbehaving. Please read here for more info ( https://www.b4x.com/android/forum/threads/app-crash-android-6-0-and-firebase-messaging.84003/)
  • If I try to Run Google Plus, it says that I must update google play services (which is a perfect behavior)
    • It Prompts me to update
    • I install the updates
  • Now if I check Google play services it shows version 11.5.xx
  • At this point my apk works perfect
Is there a way to force my apk to one of the 2 things below:
  • bundle google play service latest version
  • Prompt for update as Google Plus does

Thanks in advance
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
As far as I know Google Play Services has nothing to do with the SDK-Manager. If you compile an App it just binds resources for it.

Google Play Services are part of the OS and will be downloaded/updated by the OS seperately. I assume you have a rooted device with a non official OS which causes problems.

Never had such an issues except on a rooted device with "some" rom from the www.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
As far as I know Google Play Services has nothing to do with the SDK-Manager. If you compile an App it just binds resources for it.

Google Play Services are part of the OS and will be downloaded/updated by the OS seperately. I assume you have a rooted device with a non official OS which causes problems.

Never had such an issues except on a rooted device with "some" rom from the www.

Hi KMatle
Thanks for your input, but I have 4 different devices and none is rooted. They all behave exactly the same.

I think there should be a way, that I can have the app check Google Play Services version# and force the user to update. Just like when I click Google plus
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
You can check whether Google Play Services is installed on the device with FirebaseAnalytics.IsGooglePlayServicesAvailable.

Do you get any error message?

Hi Erel, this is one step closer.
I did a quick test and apparently this call FirebaseAnalytics.IsGooglePlayServicesAvailable returns false until GooglePlayServices is updated.
Unfortunately, it takes forever to retest as I have to keep wiping the devices. I will confirm once I'll do more testing.

Now, assuming that the above is the key to make it work. Is there a way I can display a popup that prompts the user to update GooglePlayServices?

Thanks again
You are a great help.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this code to the activity:
B4X:
Sub CheckForGooglePlayServices As Boolean
   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

Call it from Activity_Resume. It will check whether google play services is available and will allow the user to install it if not.
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Now I can cover all cases, using CheckForGooglePlayServices and FirebaseAnalytics.IsGooglePlayServicesAvailable (in different places) .

Thank you very much for your great help.
Greatly Appreciated!
 
Upvote 0
Top