我在应用购买中成功实施并且运行良好,但每当我尝试恢复以前购买的任何项目时,queryInventory()方法始终返回空库存。任何解决方案?
我是如何测试的:
我使用随机Android设备从Play商店下载了我的应用,购买了商品,删除了应用,再次下载了应用,购买了相同的商品(使用相同的帐号),再次向我收费。
使用测试设备和测试帐户连接到eclipse,购买了几个项目,然后检查queryInventory()返回库存清单大小= 0的adb logcat,但返回的结果是成功的(“BILLING_RESPONSE_RESULT_OK(0)”)。
查询广告资源代码:
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
logDebug("mHelper setup failed.");
complain("Problem setting up in-app billing: " + result);
return;
}
logDebug("mHelper setup successful. Querying inventory....");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
接收查询结果代码:
// Listener that's called when we finish querying the items we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
logDebug("Query inventory failed.");
complain("Failed to query inventory: " + result);
return;
}
logDebug("Query inventory was successful.");
// Check for items delivery
for( int i = 0; i < purchaseOptions; i++ ) {
if (inventory.hasPurchase(SKU_ITEMS[i])) {
logDebug("We have " + SKU_ITEMS[i] + " restored.");
mHelper.consumeAsync(inventory.getPurchase(SKU_ITEMS[i]), mConsumeFinishedListener);
return;
}
}
}
};