public void OnServiceConnected(ComponentName name, IBinder service) { if (outerInstance.mDisposed) { return; } outerInstance.logDebug("Billing service connected."); outerInstance.mService = IInAppBillingServiceStub.AsInterface(service); string packageName = outerInstance.mContext.PackageName; try { outerInstance.logDebug("Checking for in-app billing 3 support."); // check for in-app billing v3 support int response = outerInstance.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. outerInstance.mSubscriptionsSupported = false; return; } outerInstance.logDebug("In-app billing version 3 supported for " + packageName); // check for v3 subscriptions support response = outerInstance.mService.IsBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { outerInstance.logDebug("Subscriptions AVAILABLE."); outerInstance.mSubscriptionsSupported = true; } else { outerInstance.logDebug("Subscriptions NOT AVAILABLE. Response: " + response); } outerInstance.mSetupDone = true; } catch (RemoteException e) { if (listener != null) { listener.onIabSetupFinished(new IabResult(IABHELPER_REMOTE_EXCEPTION, "RemoteException while setting up in-app billing.")); } Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return; } if (listener != null) { listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Setup successful.")); } }
/// <summary> /// 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. /// </summary> /// <param name="listener"> The listener to notify when the setup process is complete. </param> public void startSetup(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 ServiceConnectionAnonymousInnerClassHelper(this, listener); Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.SetPackage("com.android.vending"); var list = mContext.PackageManager.QueryIntentServices(serviceIntent, 0); if ((list == null) ? false : list.Any()) { // service available to handle that Intent mContext.BindService(serviceIntent, mServiceConn, Bind.AutoCreate); } 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.")); } } }