@Override
    public boolean isBillingAvailable(final String packageName) {
        Logger.d("isBillingAvailable() packageName: ", packageName);
        if (billingAvailable != null) {
            return billingAvailable; // return previosly checked result
        }

        if (Utils.uiThread()) {
            throw new IllegalStateException("Must no be called from UI thread.");
        }

        if (!packageExists(context, ANDROID_INSTALLER) && !packageExists(context, GOOGLE_INSTALLER)) {
            Logger.d("isBillingAvailable() Google Play is not available.");
            // don't set billingAvailable variable in case Google Play gets installed later
            return false;
        }

        final Intent intent = new Intent(GooglePlay.VENDING_ACTION);
        intent.setPackage(GooglePlay.ANDROID_INSTALLER);
        final List<ResolveInfo> infoList = context.getPackageManager().queryIntentServices(intent, 0);
        if (CollectionUtils.isEmpty(infoList)) {
            Logger.e("isBillingAvailable() billing service is not available, even though Google Play application seems to be installed.");
            return false;
        }

        final CountDownLatch latch = new CountDownLatch(1);
        final boolean[] result = new boolean[1];
        final ServiceConnection serviceConnection = new ServiceConnection() {
            public void onServiceConnected(ComponentName name, IBinder service) {
                final IInAppBillingService mService = IInAppBillingService.Stub.asInterface(service);
                try {
                    final int response = mService.isBillingSupported(3, packageName, IabHelper.ITEM_TYPE_INAPP);
                    result[0] = response == IabHelper.BILLING_RESPONSE_RESULT_OK;
                } catch (RemoteException e) {
                    result[0] = false;
                    Logger.e("isBillingAvailable() RemoteException while setting up in-app billing", e);
                } finally {
                    latch.countDown();
                    context.unbindService(this);
                }
                Logger.d("isBillingAvailable() Google Play result: ", result[0]);
            }

            public void onServiceDisconnected(ComponentName name) {/*do nothing*/}
        };
        if (context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)) {
            try {
                latch.await();
            } catch (InterruptedException e) {
                Logger.e("isBillingAvailable() InterruptedException while setting up in-app billing", e);
            }
        } else {
            result[0] = false;
            Logger.e("isBillingAvailable() billing is not supported. Initialization error.");
        }
        return (billingAvailable = result[0]);
    }
@ Override public boolean isBillingAvailable ( final String packageName ) { Logger . d ( "isBillingAvailable() packageName: " , packageName ) ; if ( billingAvailable != null ) { return billingAvailable ; } if ( Utils . uiThread ( ) ) { throw new IllegalStateException ( "Must no be called from UI thread." ) ; } if ( ! packageExists ( context , ANDROID_INSTALLER ) && ! packageExists ( context , GOOGLE_INSTALLER ) ) { Logger . d ( "isBillingAvailable() Google Play is not available." ) ; return false ; } final Intent intent = new Intent ( GooglePlay . VENDING_ACTION ) ; intent . setPackage ( GooglePlay . ANDROID_INSTALLER ) ; final List < ResolveInfo > infoList = context . getPackageManager ( ) . queryIntentServices ( intent , 0 ) ; if ( CollectionUtils . isEmpty ( infoList ) ) { Logger . e ( "isBillingAvailable() billing service is not available, even though Google Play application seems to be installed." ) ; return false ; } final CountDownLatch latch = new CountDownLatch ( 1 ) ; final boolean [ ] result = new boolean [ 1 ] ; final ServiceConnection serviceConnection = new ServiceConnection ( ) { public void onServiceConnected ( ComponentName name , IBinder service ) { final IInAppBillingService mService = IInAppBillingService . Stub . asInterface ( service ) ; try { final int response = mService . isBillingSupported ( 3 , packageName , IabHelper . ITEM_TYPE_INAPP ) ; result [ 0 ] = response == IabHelper . BILLING_RESPONSE_RESULT_OK ; } catch ( RemoteException e ) { result [ 0 ] = false ; Logger . e ( "isBillingAvailable() RemoteException while setting up in-app billing" , e ) ; } finally { latch . countDown ( ) ; context . unbindService ( this ) ; } Logger . d ( "isBillingAvailable() Google Play result: " , result [ 0 ] ) ; } public void onServiceDisconnected ( ComponentName name ) { } } ; if ( context . bindService ( intent , serviceConnection , Context . BIND_AUTO_CREATE ) ) { try { latch . await ( ) ; } catch ( InterruptedException e ) { Logger . e ( "isBillingAvailable() InterruptedException while setting up in-app billing" , e ) ; } } else { result [ 0 ] = false ; Logger . e ( "isBillingAvailable() billing is not supported. Initialization error." ) ; } return ( billingAvailable = result [ 0 ] ) ; }
Assume Android app is published in Google Play in any case.
<ul><li>
- check Google Play package is installed<li>
- check Google Play Vending service is available<li>
- check Google Play Vending supports v3 items TYPE_IN-APP (false if Google Play account doesn't exist)
</ul>

@return true if Google Play is installed in the system