我正在尝试在我的应用程序中进行应用程序购买,但出了点问题。我从本教程中做了所有内容:http://developer.android.com/training/in-app-billing/purchase-iab-products.html和stackoverflows解决方案但是id没有帮助,我在运行应用程序后仍然收到此错误:java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: queryInventory
由响应RESULT_BILLING_UNAVAILABLE
引起它在调用方法之后发生mHelper.queryInventoryAsync(mGotInventoryListener);
这是我在活动中的onCreate代码:
mHelper = new IabHelper(this, string1 + string2 + string3);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
if (mHelper == null) return;
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
和活动中的变量定义:
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (mHelper == null) return;
if (result.isFailure()) {
Log.e(TAG, "**** TrivialDrive Error: " + "Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
Purchase farmPurchase = inventory.getPurchase(Constants.SKU_FARM);
isFarm = (farmPurchase != null);
Log.d(TAG, "User is " + (isFarm ? "FARM" : "NOT FARM"));
Purchase birdsPurchase = inventory.getPurchase(Constants.SKU_BIRDS);
isBirds = (birdsPurchase != null);
Log.d(TAG, "User " + (isBirds ? "BIRDS" : "NOT BIRDS"));
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
我错过了重要的事情吗?