So we want to support in-app billing via Google's billing API and via AliPay for China. I've written a method that should return either a GooglePlay or an AliPay billing client (whichever is available). I need a way to determine whether Google's billing service is available to the user so I know which client to return.
So far I've come across a few different options and I'm unsure which one is the one I need:
- Create a
ServiceConnection
and check the result ofIInAppBillingService.Stub.asInterface(service) .isBillingSupported(3, context.packageName, "inapp")
Here's the full code: https://gist.github.com/first087/9088162
This is a bit tedious since I need to wait for the service to connect, get the asynchronous result and then return the correct billing manager, but at first glance seems to be exactly what I need.
- Use the
GoogleApiAvailability
class and check the result ofisGooglePlayServicesAvailable(context)
This option is a lot cleaner than the 1st one, but I'm unsure whether it returns what I need and also requires me to add the com.google.android.gms:play-services-base
library to my project.
- Check if the GooglePlay app is installed on the device.
This is the most unreliable option (I think), because you can manually install the app, even though it's not been pre-installed by the manufacturer, and then you might not be able to make purchases since you're in China and they don't allow that.
Has anybody had similar experience? How do I correctly determine whether the user can make purchases via the PlayStore?
BillingClient.isFeatureSupported()
– Bramblett