예제 #1
0
        protected override void OnDestroy()
        {
            if (_serviceConnection != null)
            {
                _serviceConnection.Disconnected();
            }

            base.OnDestroy();
        }
예제 #2
0
        private async void AboutPageDonateButtonOnClick(View view)
        {
            InAppBillingServiceConnection connection = null;

            try
            {
                connection = new InAppBillingServiceConnection(Activity);
                var sem = new SemaphoreSlim(0);
                connection.OnConnected += (sender, args) => sem.Release();
                connection.Connect();
                if (await sem.WaitAsync(TimeSpan.FromSeconds(5)))
                {
                    var buyIntentBundle = connection.Service.GetBuyIntent(3, Context.PackageName,
                                                                          GetProductSku(), "inapp", "");
                    var pendingIntent = buyIntentBundle.GetParcelable("BUY_INTENT") as PendingIntent;
                    MainActivity.CurrentContext.StartIntentSenderForResult(pendingIntent.IntentSender, 1001, new Intent(), 0, 0, 0, Bundle.Empty);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                ResourceLocator.MessageDialogProvider.ShowMessageDialog("Something went wrong, you can always try later ^^", "Something went wrong™");
            }
            finally
            {
                connection.Disconnected();
            }

            string GetProductSku()
            {
                switch (view.Id)
                {
                case Resource.Id.AboutPageDonate1Button:
                    return("donation1");

                case Resource.Id.AboutPageDonate2Button:
                    return("donate2");

                case Resource.Id.AboutPageDonate3Button:
                    return("donate3");

                case Resource.Id.AboutPageDonate4Button:
                    return("donate4");

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
예제 #3
0
        private async void AboutPageDonateButtonOnClick(View view)
        {
            InAppBillingServiceConnection connection = null;

            try
            {
                connection = new InAppBillingServiceConnection(Activity);
                var sem = new SemaphoreSlim(0);
                connection.OnConnected += (sender, args) => sem.Release();
                connection.Connect();
                if (await sem.WaitAsync(TimeSpan.FromSeconds(5)))
                {
                    //first try to redeem all existing ones
                    var ownedItems = connection.Service.GetPurchases(3, Context.PackageName, "inapp", null);
                    if (ownedItems.GetInt("RESPONSE_CODE") != 0)
                    {
                        throw new Exception();
                    }

                    // Get the list of purchased items
                    foreach (var purchaseData in ownedItems.GetStringArrayList("INAPP_PURCHASE_DATA_LIST"))
                    {
                        var o             = new JSONObject(purchaseData);
                        var purchaseToken = o.OptString("token", o.OptString("purchaseToken"));
                        // Consume purchaseToken, handling any errors
                        connection.Service.ConsumePurchase(3, Context.PackageName, purchaseToken);
                    }

                    var buyIntentBundle = connection.Service.GetBuyIntent(3, Context.PackageName,
                                                                          GetProductSku(), "inapp", "");
                    var pendingIntent = buyIntentBundle.GetParcelable("BUY_INTENT") as PendingIntent;
                    MainActivity.CurrentContext.StartIntentSenderForResult(pendingIntent.IntentSender, 1001,
                                                                           new Intent(), 0, 0, 0, Bundle.Empty);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                ResourceLocator.MessageDialogProvider.ShowMessageDialog(
                    "Something went wrong, you can always try later ^^", "Something went wrong™");
            }
            finally
            {
                connection?.Disconnected();
            }

            string GetProductSku()
            {
                switch (view.Id)
                {
                case Resource.Id.AboutPageDonate1Button:
                    return("donation1");

                case Resource.Id.AboutPageDonate2Button:
                    return("donate2");

                case Resource.Id.AboutPageDonate3Button:
                    return("donate3");

                case Resource.Id.AboutPageDonate4Button:
                    return("donate4");

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }