I'm calling queryinventoryasync from the xamarin in-app billing component for android but I'm always receiving 0 products returned even though I have added 4 in-app products in google play. I have done the following to try and get it working:
Here's my code:
static internal InAppBillingServiceConnection _serviceConnection;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_serviceConnection = new InAppBillingServiceConnection(this, APP_KEY);
_serviceConnection.OnInAppBillingError += ServiceConnection_OnInAppBillingError;
_serviceConnection.OnConnected += () =>
{
GetInventory();
};
_serviceConnection.Connect();
global::Xamarin.Forms.Forms.Init(this, bundle);
Core.App.ALLOW_ADULT_SWITCH = false;
LoadApplication(new Core.App());
}
//For testing purposes only.
private async void GetInventory()
{
var products = await _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string>
{
ReservedTestProductIDs.Purchased
},
ItemType.Product);
if (products == null)
{
return;
}
}
private void ServiceConnection_OnInAppBillingError(InAppBillingErrorType error, string message)
{
throw new System.Exception(message);
}
protected override void OnDestroy()
{
if (_serviceConnection != null && _serviceConnection.Connected)
_serviceConnection.Disconnect();
_serviceConnection = null;
base.OnDestroy();
}
God this was a nightmare to get working! Here's what I did,
1) Skipped queryinventoryasync call and focussed on method BuyProduct(situation.PurchaseId, ItemType.Product, user.EmailAddress); This overload allows you to skip queryinventoryasync by passing in the product id directly.
2) With this in place I started using the androids reserved test id's and it worked. But actual product id's didn't work.
3) I uploaded a new apk and clicked on publish while in alpha testing, the publish button is placed in a non-intuitive place. But apparently if publish is pressed while in alpha testing, it will only be released to your testers.
4) Log in as tester on browser and click on the opt-in link within google developer console to register as a tester with google play.
5) Debug version of app will not work with in-app products, you have to manually download the version of the app from googleplay from your device and install, then run, and you can test your in-app products finally !!!