getPurchases
needs an Integer that is representing the InApp Billing API. So your call
Bundle ownedItems = mService.getPurchases(6, getPackageName(), "inapp", null);
must be handling the api version. If you developing InApp Billing version 3, it must be:
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
Like described in API:
Pass the In-app Billing API version (“3”), the package name of your calling app, and the purchase type (“inapp” or "subs") into the method. Here is an example:
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null)
;
I wonder why it works, anyway I don´t think that this is causing the problem.
The next thing is, the getPurchases()
returns only not consumed items. If your items are consumed, it will not return these. That´s why history returns it. Like described in API:
getPurchases()
This method returns the current un-consumed products owned by the user, including both purchased items and items acquired by redeeming a promo code.
getPurchaseHistory()
This method returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
My experience with inApp Billing is that this is a huge pain as it is not possible to test every cirumstances through a test account. It seems like a not finished part of android. But we have no other choice to follow exact the api, so I recommend to do it exactly like described.
API and Source Codes:
https://developer.android.com/google/play/billing/billing_integrate.html
https://developer.android.com/google/play/billing/billing_reference.html
https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive/app/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl