Android InAppBilling使用Xamarin.InappBilling

时间:2014-06-26 13:49:22

标签: android xamarin.ios xamarin

我正在尝试在我正在使用Xamarin.InAPPBilling开发的android-app中实现InAppBilling。我遇到的问题是,当我尝试调用连接的计费处理程序返回可用产品列表时,它不会返回任何内容。所以我想知道是否有一些我在这个非常简单的例子中搞砸了或是因为我需要配置一些我的developperaccount以便能够测试它?此外,当我写一个空字符串,其中连接的键应该是,我仍然可以连接到谷歌播放。这是正常的吗?任何帮助将不胜感激!

namespace TestInapp
{
[Activity (Label = "TestInapp", MainLauncher = true)]

public class Activity1 : Activity
{
    Button button;
    IList<Product> _products;

    private InAppBillingServiceConnection _serviceConnection;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        Console.WriteLine ("Program starts");
        // Set our view from the "main" layout resource

        SetContentView (Resource.Layout.Main);

        _products = new List<Product> ();

        StartSetup ();

    }

    public void StartSetup()
    {
        // Create a new connection to the Google Play Service
        _serviceConnection = new InAppBillingServiceConnection (this, string.Empty);
        _serviceConnection.OnConnected += async () => {
            Console.WriteLine("Connected to GooglePlay");
            await GetInventory ();
        };
        _serviceConnection.Connect ();
    }

    async Task GetInventory()
    {
        Console.WriteLine ("Starting to find available products");

        _products = await _serviceConnection.BillingHandler.QueryInventoryAsync (new List<String>{
            "Produkt1",
            "Produkt2"
        }, ItemType.Product);

        Console.WriteLine ("Finished finding available products");

        if (_products == null) {
            Console.WriteLine ("No products available");
            return;
        } else  Console.WriteLine ("Products available");

        foreach (var p in _products) 
        {
            Console.WriteLine (p.ToString());
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

在测试您自己的产品之前,有一些事情要设置(在de google play dev帐户中)。但您可以在以下测试特殊测试产品:

_products = await _serviceConnection.BillingHandler.QueryInventoryAsync (new List<string>     {
            ReservedTestProductIDs.Purchased,
            ReservedTestProductIDs.Canceled,
            ReservedTestProductIDs.Refunded,
            ReservedTestProductIDs.Unavailable
        }, ItemType.Product);