java – 在哪里恢复用户的应用程序内购买?
发布时间:2020-12-15 02:15:38 所属栏目:Java 来源:网络整理
导读:我一直在关注垃圾谷歌教程,但它没有提到在何处放置代码来恢复用户购买.在TD教程中它写道: try { mHelper.queryInventoryAsync(mGotInventoryListener);} catch (IabAsyncInProgressException e) { complain("Error querying inventory. Another async opera
|
我一直在关注垃圾谷歌教程,但它没有提到在何处放置代码来恢复用户购买.在TD教程中它写道:
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabAsyncInProgressException e) {
complain("Error querying inventory. Another async operation in progress.");
}
在startSetup()方法中,这是我写的和我把它放在哪里的? 解决方法
您可以在应用中的任何位置检索有关用户购买的信息.
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的地方使用此代码 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
