【问题标题】:Android: In App Billing returns only 1 purchaseAndroid:应用内结算仅返回 1 次购买
【发布时间】:2017-04-25 05:17:58
【问题描述】:

我已将所有产品添加为托管产品。当我查询 getPurchases 时,它只返回 1 项,但当我查询 getHistory 时,它返回 3 项我很困惑为什么会这样?

获取购买代码:

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

获取购买历史代码:

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

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

【问题讨论】:

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


    【解决方案1】:

    getPurchases 需要一个表示 InApp 计费 API 的整数。所以你的电话

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

    必须处理 api 版本。如果您开发 InApp Billing 版本 3,它必须是:

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

    如 API 中所述:

    将 In-app Billing API 版本(“3”)、调用应用的包名称和购买类型(“inapp”或“subs”)传递到方法中。这是一个例子:

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

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

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

    getPurchases()
    

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

    getPurchaseHistory()
    

    此方法返回用户为每个 SKU 进行的最近一次购买,即使该购买已过期、取消或消耗。

    我对应用内计费的体验是,这是一个巨大的痛苦,因为不可能通过测试帐户测试所有情况。这似乎是 android 的未完成部分。但是我们没有其他选择来完全遵循 api,所以我建议完全按照描述的方式进行。

    API 和源代码:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      相关资源
      最近更新 更多