【问题标题】:Where do you restore the users In-App Purchases?你在哪里恢复用户的应用内购买?
【发布时间】:2016-11-15 10:33:37
【问题描述】:

我一直在关注垃圾谷歌教程,但它没有提到将代码放在哪里来恢复用户购买。在 TD 教程中它写道:

try {
  mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabAsyncInProgressException e) {
  complain("Error querying inventory. Another async operation in progress.");
}

在startSetup() 方法中,这是我写的吗?我把它放在哪里了?

【问题讨论】:

  • 垃圾谷歌教程哈哈。是错字还是?
  • 不,关于 IAP 的指南非常糟糕,毫无意义。

标签: java android in-app-purchase billing


【解决方案1】:

您可以在应用中的任何位置检索有关用户购买的信息。

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
   ArrayList<String> ownedSkus =
      ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
   ArrayList<String>  purchaseDataList =
      ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
   ArrayList<String>  signatureList =
      ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
   String continuationToken =
      ownedItems.getString("INAPP_CONTINUATION_TOKEN");

   for (int i = 0; i < purchaseDataList.size(); ++i) {
      String purchaseData = purchaseDataList.get(i);
      String signature = signatureList.get(i);
      String sku = ownedSkus.get(i);

      // do something with this purchase information
      // e.g. display the updated list of products owned by user
   }

   // if continuationToken != null, call getPurchases again
   // and pass in the token to retrieve more items
}

您可以在任何想要恢复用户购买的地方使用此代码

【讨论】:

  • 我说的方式不是推荐的方式吗?我看到了你这样做的方式,但在一个较旧的指南中。
  • getPurchases() 是获取已购买商品捆绑包的 API。如何使用捆绑包由您决定。
  • 在您重新回复之前,我使用了 onQuery 和:Purchase lessonOnePurchase = inventory.getPurchase(SKU_bl1); isPurchased_basiclesson1 = (lessonOnePurchase != null &amp;&amp; verifyDeveloperPayload(lessonOnePurchase));,这是一个问题吗?
  • 一点也不!这样你就可以在任何你想要的地方使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
相关资源
最近更新 更多