Example usage for android.content ServiceConnection ServiceConnection

List of usage examples for android.content ServiceConnection ServiceConnection

Introduction

In this page you can find the example usage for android.content ServiceConnection ServiceConnection.

Prototype

ServiceConnection

Source Link

Usage

From source file:org.onepf.oms.appstore.googleUtils.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * @param listener The listener to notify when the setup process is complete.
 *///from w w w .  j  av a  2s .  c  om
public void startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            logDebug("Billing service connected.");
            mService = getServiceFromBinder(service);
            componentName = name;
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are subscriptions.
                    mSubscriptionsSupported = false;
                    return;
                }
                logDebug("In-app billing version 3 supported for " + packageName);

                // check for v3 subscriptions support
                response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscriptions AVAILABLE.");
                    mSubscriptionsSupported = true;
                } else {
                    logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                Log.e(TAG, "RemoteException while setting up in-app billing", e);
                return;
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = getServiceIntent();
    final List<ResolveInfo> infoList = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
    if (infoList != null && !infoList.isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (listener != null) {
            listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    "Billing service unavailable on device."));
        }
    }
}

From source file:it.baywaylabs.jumpersumo.MainActivity.java

private void initServiceConnection() {
    ardiscoveryServiceConnection = new ServiceConnection() {
        @Override/*from  w  w  w.j a  v a  2 s  .  co  m*/
        public void onServiceConnected(ComponentName name, IBinder service) {
            discoveryServiceBinder = service;
            ardiscoveryService = ((ARDiscoveryService.LocalBinder) service).getService();
            ardiscoveryServiceBound = true;

            ardiscoveryService.start();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            ardiscoveryService = null;
            ardiscoveryServiceBound = false;
        }
    };
}

From source file:com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.IAB.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * THIS WILL NOT WORK ON an EMULATOR, YOU NEED A REAL DEVICE
 *
 * @param listener The listener to notify when the setup process is complete.
 *//*  w ww.  j  a  va 2 s  . c  o m*/
public void startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null) {
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));
                    }
                    return;
                }
                logDebug("In-app billing version 3 supported for " + packageName);
                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    boolean attempt = mContext.getApplicationContext()
            .bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                    .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);

    if (!attempt) {
        Log.e(mDebugTag,
                "Failed to bind to Service with name com.android.vending.billing.InAppBillingService.BIND");
    }
}

From source file:mc.inappbilling.v3.InAppBillingHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously. You will be notified through the
 * listener when the setup process is complete. This method is safe to call from a UI thread.
 * /*from  w w  w. j ava2 s  .co m*/
 * @param listener
 *            The listener to notify when the setup process is complete.
 */
public boolean startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    if (mSetupDone) {
        logError(LOGTAG + " is already set up.");
        return true;
    }

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
            if (mService != null) {
                logDebug("Billing service connected.");
                String packageName = mContext.getPackageName();
                try {
                    logDebug("Checking for in-app billing 3 support.");
                    int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                    if (response != BILLING_RESPONSE_RESULT_OK) {
                        if (listener != null) {
                            listener.onIabSetupFinished(
                                    new InAppBillingResult(response, "Error checking for billing v3 support."));
                        }
                        return;
                    }
                    logDebug("In-app billing version 3 supported for " + packageName);
                    mSetupDone = true;
                } catch (RemoteException e) {
                    if (listener != null) {
                        listener.onIabSetupFinished(new InAppBillingResult(IABHELPER_REMOTE_EXCEPTION,
                                "RemoteException while setting up in-app billing."));
                    }
                    e.printStackTrace();
                    return;
                }

                if (listener != null) {
                    listener.onIabSetupFinished(
                            new InAppBillingResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
                }
                return;
            }
            if (listener != null) {
                logError("Billing service is null.");
                listener.onIabSetupFinished(
                        new InAppBillingResult(IABHELPER_UNKNOWN_ERROR, "Cannot connect to billing service."));
            }
        }
    };
    return mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
            mServiceConn, Context.BIND_AUTO_CREATE);
}

From source file:com.clover.android.sdk.examples.InventoryTestActivity.java

private void connectToInventoryService() {
    serviceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            inventoryService = IInventoryService.Stub.asInterface(service);
            serviceIsBound = true;// w w w.j  a  va  2 s. com
            statusText.setText("connected to AIDL service");
            fetchItemsFromService();
            createObjectsUsingService();
        }

        public void onServiceDisconnected(ComponentName className) {
            statusText.setText("disconnected from AIDL service");
            inventoryService = null;
            serviceIsBound = false;
        }
    };

    Account account = CloverAccount.getAccount(this);
    Intent intent = new Intent(InventoryIntent.ACTION_INVENTORY_SERVICE_V3);
    intent.putExtra(Intents.EXTRA_ACCOUNT, account);
    bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}

From source file:paulscode.android.mupen64plusae.jni.CoreFragment.java

private void actuallyStartCore(Activity activity) {
    if (!mIsRunning) {
        mIsRunning = true;/*from  w w w.j  av a  2s .c om*/

        // Defines callbacks for service binding, passed to bindService()
        mServiceConnection = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName className, IBinder service) {

                // We've bound to LocalService, cast the IBinder and get LocalService instance
                LocalBinder binder = (LocalBinder) service;
                mCoreService = binder.getService();
                mCoreService.setSurface(mSurface);
                mCoreService.setOnFpsChangedListener(mFpsChangeListener, mFpsRecalcPeriod);
                mCoreService.setCoreServiceListener(CoreFragment.this);

                if (mCoreEventListener != null && getActivity() != null) {
                    mCoreEventListener.onCoreServiceStarted();
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName arg0) {
                //Nothing to do here
            }
        };

        ArrayList<Integer> pakTypes = new ArrayList<>();
        pakTypes.add(mGlobalPrefs.getPakType(1).getNativeValue());
        pakTypes.add(mGlobalPrefs.getPakType(2).getNativeValue());
        pakTypes.add(mGlobalPrefs.getPakType(3).getNativeValue());
        pakTypes.add(mGlobalPrefs.getPakType(4).getNativeValue());

        boolean[] isPlugged = new boolean[4];
        isPlugged[0] = mGamePrefs.isPlugged1;
        isPlugged[1] = mGamePrefs.isPlugged2;
        isPlugged[2] = mGamePrefs.isPlugged3;
        isPlugged[3] = mGamePrefs.isPlugged4;

        // Start the core
        ActivityHelper.startCoreService(activity.getApplicationContext(), mServiceConnection, mRomGoodName,
                mRomPath, mRomMd5, mRomCrc, mRomHeaderName, mRomCountryCode, mRomArtPath, mRomLegacySave,
                mCheatArgs, mIsRestarting, mSaveToLoad, mAppData.coreLib, mGlobalPrefs.useHighPriorityThread,
                pakTypes, isPlugged, mGlobalPrefs.isFramelimiterEnabled, mGlobalPrefs.coreUserDataDir,
                mGlobalPrefs.coreUserCacheDir, mGamePrefs.coreUserConfigDir, mGamePrefs.userSaveDir,
                mAppData.libsDir);
    }
}

From source file:bulat.diet.helper_sport.utils.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process
 * asynchronously. You will be notified through the listener when the setup
 * process is complete. This method is safe to call from a UI thread.
 * //ww w.ja  v a 2 s .  co  m
 * @param listener
 *            The listener to notify when the setup process is complete.
 */
public void startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    checkNotDisposed();
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are
                    // subscriptions.
                    mSubscriptionsSupported = false;
                    return;
                }
                logDebug("In-app billing version 3 supported for " + packageName);

                // check for v3 subscriptions support
                response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscriptions AVAILABLE.");
                    mSubscriptionsSupported = true;
                } else {
                    logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    try {
        if (mContext != null && !mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
            // service available to handle that Intent
            mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        } else {
            // no service available to handle that Intent
            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                        "Billing service unavailable on device."));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.smartmobilesoftware.util.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * @param listener The listener to notify when the setup process is complete.
 *//*w ww. j  a va 2s .  com*/
public void startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    checkNotDisposed();
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are subscriptions.
                    mSubscriptionsSupported = false;
                    mSubscriptionUpdateSupported = false;
                    return;
                } else {
                    logDebug("In-app billing version 3 supported for " + packageName);
                }

                // Check for v5 subscriptions support. This is needed for
                // getBuyIntentToReplaceSku which allows for subscription update
                response = mService.isBillingSupported(5, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscription re-signup AVAILABLE.");
                    mSubscriptionUpdateSupported = true;
                } else {
                    logDebug("Subscription re-signup not available.");
                    mSubscriptionUpdateSupported = false;
                }

                if (mSubscriptionUpdateSupported) {
                    mSubscriptionsSupported = true;
                } else {
                    // check for v3 subscriptions support
                    response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                    if (response == BILLING_RESPONSE_RESULT_OK) {
                        logDebug("Subscriptions AVAILABLE.");
                        mSubscriptionsSupported = true;
                    } else {
                        logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                        mSubscriptionsSupported = false;
                        mSubscriptionUpdateSupported = false;
                    }
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(ERR_COMMUNICATION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    try {
        PackageManager pm = mContext.getPackageManager();
        List<ResolveInfo> intentServices = pm.queryIntentServices(serviceIntent, 0);

        if (intentServices != null && !intentServices.isEmpty()) {
            // service available to handle that Intent
            mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
            return;
        }
    } catch (NullPointerException e) {
        // unexpected failure while accessing the service,
        // report the error.
        if (listener != null) {
            listener.onIabSetupFinished(
                    new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Billing service failed to initialize."));
        }
        return;
    }
    // no service available to handle that Intent
    if (listener != null) {
        listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Billing service unavailable on device."));
    }
}

From source file:land.aseman.android.store.util.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * @param listener The listener to notify when the setup process is complete.
 *///  w w w . j av  a  2 s.c o m
public void startSetup(String storePackageName, String billingBindIntentPath,
        final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    checkNotDisposed();
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are subscriptions.
                    mSubscriptionsSupported = false;
                    return;
                }
                logDebug("In-app billing version 3 supported for " + packageName);

                // check for v3 subscriptions support
                response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscriptions AVAILABLE.");
                    mSubscriptionsSupported = true;
                } else {
                    logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = new Intent(billingBindIntentPath);
    serviceIntent.setPackage(storePackageName);
    if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (listener != null) {
            listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    "Billing service unavailable on device."));
        }
    }
}

From source file:com.android.trivialdrivesample.util.IabHelper.java

/**
 * Starts the setup process. This will start up the setup process asynchronously.
 * You will be notified through the listener when the setup process is complete.
 * This method is safe to call from a UI thread.
 *
 * @param listener The listener to notify when the setup process is complete.
 *///from www .  j a v  a2  s .co  m
public void startSetup(final OnIabSetupFinishedListener listener) {
    // If already set up, can't do it again.
    checkNotDisposed();
    if (mSetupDone)
        throw new IllegalStateException("IAB helper is already set up.");

    // Connection to IAB service
    logDebug("Starting in-app billing setup.");
    mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            logDebug("Billing service disconnected.");
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if (mDisposed)
                return;
            logDebug("Billing service connected.");
            mService = IInAppBillingService.Stub.asInterface(service);
            String packageName = mContext.getPackageName();
            try {
                logDebug("Checking for in-app billing 3 support.");

                // check for in-app billing v3 support
                int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    if (listener != null)
                        listener.onIabSetupFinished(
                                new IabResult(response, "Error checking for billing v3 support."));

                    // if in-app purchases aren't supported, neither are subscriptions
                    mSubscriptionsSupported = false;
                    mSubscriptionUpdateSupported = false;
                    return;
                } else {
                    logDebug("In-app billing version 3 supported for " + packageName);
                }

                // Check for v5 subscriptions support. This is needed for
                // getBuyIntentToReplaceSku which allows for subscription update
                response = mService.isBillingSupported(5, packageName, ITEM_TYPE_SUBS);
                if (response == BILLING_RESPONSE_RESULT_OK) {
                    logDebug("Subscription re-signup AVAILABLE.");
                    mSubscriptionUpdateSupported = true;
                } else {
                    logDebug("Subscription re-signup not available.");
                    mSubscriptionUpdateSupported = false;
                }

                if (mSubscriptionUpdateSupported) {
                    mSubscriptionsSupported = true;
                } else {
                    // check for v3 subscriptions support
                    response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS);
                    if (response == BILLING_RESPONSE_RESULT_OK) {
                        logDebug("Subscriptions AVAILABLE.");
                        mSubscriptionsSupported = true;
                    } else {
                        logDebug("Subscriptions NOT AVAILABLE. Response: " + response);
                        mSubscriptionsSupported = false;
                        mSubscriptionUpdateSupported = false;
                    }
                }

                mSetupDone = true;
            } catch (RemoteException e) {
                if (listener != null) {
                    listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION,
                            "RemoteException while setting up in-app billing."));
                }
                e.printStackTrace();
                return;
            }

            if (listener != null) {
                listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
            }
        }
    };

    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (listener != null) {
            listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                    "Billing service unavailable on device."));
        }
    }
}