Android:在应用结算中仅返回1次购买

时间:2017-04-25 05:17:58

标签: android in-app-billing android-developer-api

我已将所有产品添加为被管理产品。当我查询getPurchases时,它只返回1个项目但是当我查询getHistory时它返回3个项目我很困惑为什么它正在发生?

购买代码:

Bundle ownedItems = mService.getPurchases(6, getPackageName(), "inapp", null);

获取购买历史代码:

 Bundle purchaseHistoryBundle = mService.getPurchaseHistory(6, getPackageName(), "inapp", null, new Bundle());

我购买了很多产品如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

getPurchases需要一个代表InApp Billing API的Integer。所以你的电话

Bundle ownedItems = mService.getPurchases(6, getPackageName(), "inapp", null);

必须处理api版本。如果您开发InApp结算版本3,则必须是:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

如API中所述:

将应用内结算API版本(“3”),您的通话应用的套餐名称以及购买类型(“inapp”或“subs”)传递到方法中。这是一个例子:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

我想知道它为什么会起作用,无论如何我不认为这会导致问题。

接下来,getPurchases()仅返回不消耗的项目。如果您的物品被消耗,它将不会返回这些物品。这就是历史回归的原因。如API中所述:

getPurchases()

此方法返回用户拥有的当前未消费产品,包括购买的商品和通过兑换促销代码获得的商品。

getPurchaseHistory()

此方法会返回用户为每个SKU进行的最新购买,即使该购买已过期,已取消或已消费。

我对inApp Billing的经验是,这是一个巨大的痛苦,因为无法通过测试帐户测试每个环境。这似乎是一个未完成的android部分。但我们别无选择地遵循api,所以我建议完全按照描述进行。

API和源代码:

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

{{3}}