public void OnServiceConnected(ComponentName name, IBinder service) { Service = InAppBillingServiceStub.AsInterface(service); if (Service == null || Context == null) { tcsConnect?.TrySetResult(false); return; } var pkgName = Context.PackageName; var type = itemType == ItemType.Subscription ? ITEM_TYPE_SUBSCRIPTION : ITEM_TYPE_INAPP; try { if (Service.IsBillingSupported(3, pkgName, type) == 0) { IsConnected = true; tcsConnect?.TrySetResult(true); return; } } catch (System.Exception ex) { Console.WriteLine("Unable to check if billing is supported: " + ex.Message); } tcsConnect?.TrySetResult(false); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="service"></param> public void OnServiceConnected(ComponentName name, IBinder service) { try { Connected = true; InAppService = InAppBillingServiceStub.AsInterface(service); var packageName = MainContext.PackageName; Utils.LogDebug("InAppService connected. Checking for v3 support."); if (InAppService.IsBillingSupported(3, packageName, Consts.ITEM_TYPE_INAPP) != Consts.BILLING_RESPONSE_RESULT_OK) { //If in-app items are not supported, subscriptions are not as well. PurchasesSupported = SubscriptionsSupported = false; return; } PurchasesSupported = true; Utils.LogDebug("InAppService v3 is supported."); if (InAppService.IsBillingSupported(3, packageName, Consts.ITEM_TYPE_SUBS) != Consts.BILLING_RESPONSE_RESULT_OK) { Utils.LogDebug("Subscriptions are not available."); SubscriptionsSupported = true; } else { Utils.LogDebug("Subscriptions are not available."); } if (m_listener != null) { m_listener.Connected(); } } catch (RemoteException e) { Utils.LogError("Remote exception occurred in OnServiceConnected; " + e.ToString()); Connected = false; } finally { //Just indicates that the connect request has completed // check PurchasesSupported to know whether or not v3 is supported, if successful if (m_connectTcs != null) { m_connectTcs.SetResult(this.Connected); } } }