您在哪里恢复用户的应用程序内购买?

时间:2016-07-13 02:00:15

标签: java android in-app-purchase billing

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

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

startSetup()方法中,这是我写的内容和放在哪里的吗?

1 个答案:

答案 0 :(得分:0)

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

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
}

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