Android Question Checking for GooglePlay installed

Robert Valentino

Well-Known Member
Licensed User
Longtime User
My app keeps crashing in the BillingManager.Initialize
Code: Copy
~i:** Service (starter) Create **
~i:** Service (starter) Start **
~e:starter_service_start (java line: 1039) ~e:java.lang.NullPointerException
~e:  at anywheresoftware.b4a.objects.IbHelper.startSetup(IbHelper.java:269)
~e:  at anywheresoftware.b4a.inappbilling3.BillingManager3.Initialize(BillingManager3.java:44)
~e:  at com.BOBs.BBS.starter._service_start(starter.java:1039)

NOW the Initialize routine works fine on 3 different devices I have all different size and android version.

I believe this has something to do with GooglePlay not being installed? Or them not having an account setup.

How do I figure out what is causing the crash in BillingManager.Initialize or at least trap the error so I can leave the starter routine gracefully and inform the user of what they need to do.

Not sure how they would have my app running if they don't have GooglePlay installed and a valid account. How would then download it from GooglePlay site?

Would using the following code help me determine if GooglePlay is installed and the have a Google account setup?

Code: Copy
Dim mPackageManager AsPackageManagerDim GooglePlayServicesVersion As Int
GooglePlayServicesVersion = mPackageManager.GetVersionCode("com.google.android.gms")

Does anyone know that the above code returns if GooglePlay services are NOT installed?
 
I found this code on the web
Code: Copy
GoogleApiAvailability api =GoogleApiAvailability.getInstance();
int code = api.isGooglePlayServicesAvailable(activity);
if(code ==ConnectionResult.SUCCESS){
// Do Your Stuff Here}
else{
AlertDialog alertDialog =newAlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle).setMessage("You need to download Google Play Services in order to use this part of the application").create();
alertDialog.show();}

and I just found this code on our site

Code: Copy
Private MapFragment1 As MapFragment

If MapFragment1.IsGooglePlayServicesAvailable = FalseThenToastMessageShow("Please install Google Play Services.", True)EndIf

But does this require google maps?

And also found this
Code: Copy
Dim GooglePlayServicesHelper1 As GooglePlayServicesHelperDim ServiceStatus As Int=GooglePlayServicesHelper1.IsGooglePlayServicesAvailable
 Select ServiceStatusCase GooglePlayServicesHelper1.SUCCESSLog("GooglePlayServicesHelper IsGooglePlayServicesAvailable service available")
 LocationClient1.Initialize("LocationClient1")
 LocationClient1.ConnectCaseElseLog("GooglePlayServicesHelper IsGooglePlayServicesAvailable returned: "&ServiceStatus)EndSelect
 
Upvote 0
Following this example (https://www.b4x.com/android/forum/threads/google-maps.63930/#content) for google maps I am now able to test google services using example:
Code: Copy
Private MapFragment1 As  MapFragment
If MapFragment1.IsGooglePlayServicesAvailable = False Then
  ToastMessageShow("Please install Google Play Services.", True)
EndIf

That's great I know if it is available or not.

Is there a way for me to do the
Code: Copy
GoogleApiAvailability api =GoogleApiAvailability.getInstance();

int code = api.isGooglePlayServicesAvailable(activity);

So I can get actual status of why GooglePlayServices are not available

BobVal
 
Upvote 0
Seems to have everything working.

But a lot of stuff I had to add.

Firebase, Google maps all to check if google play services are available.

Seems like there needs to be a better way.
 
Upvote 0
Back
Top