Java – where to restore the user’s purchase within the application?

I've been following the junk Google tutorial, but it doesn't mention where to put code to restore user purchases In the TD tutorial, it says:

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

In the startsetup () method, I wrote this and where did I put it?

Solution

You can retrieve information about user purchases anywhere in the application

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
}

You can use this code anywhere you want to restore user purcahse

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>