Xamarin安卓应用内购买0

时间:2017-05-29 10:10:03

标签: android xamarin google-play in-app-purchase

不知何故谷歌一直告诉我的用户(我的应用)该用户已经购买了0件物品。 但他们确实做到了!

这是wat返回0:

_purchase = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);

Toast.MakeText(GetThis(), "You have bought " + _purchase.Count + " products", ToastLength.Long).Show();

_purchase是private IList<Purchase> _purchase;

这就是我OnCreate()的样子:

// Create a new connection to the Google Play Service
_serviceConnection = new InAppBillingServiceConnection(this, "VERRY LONG STRING");
_serviceConnection.OnConnected += async () =>
{
    _products = await _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string> {
        "all"
    }, ItemType.Product);

    // Were any products returned?
    if (_products == null)
    {
        Toast.MakeText(GetThis(), "Something wen't wrong", ToastLength.Long).Show();
        // No, abort
        return;
    }

    if (!payed)
    {
        // Not paid atleast not saved
        _purchase = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);

        Toast.MakeText(GetThis(), "You have bought " + _purchase.Count + " products", ToastLength.Long).Show();

        if (_purchase.Count == 0)
        {
            payed = true;

            ISharedPreferencesEditor editor = prefs.Edit();
            editor.PutBoolean("payed", payed);
            editor.Apply();
        }
    }
    else
    {
        Toast.MakeText(GetThis(), "thanks!", ToastLength.Long).Show();
    }

    BuildDefaultButtons();
};

// Attempt to connect to the service
_serviceConnection.Connect();

由于我的应用程序已投入生产,因此非常烦人。当我用促销代码自己测试时,我发现了这个大问题。

0 个答案:

没有答案