gpt4 book ai didi

Android 应用内结算 v3 : "Can' t perform operation: queryInventory"

转载 作者:IT老高 更新时间:2023-10-28 21:54:48 25 4
gpt4 key购买 nike

我首次使用新的 v3 API 设置了应用内结算。它在我的设备上正常运行,但我收到了很多其他用户的错误报告。

其中一个是:

java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: queryInventory
at my.package.util.iab.IabHelper.checkSetupDone(IabHelper.java:673)
at my.package.util.iab.IabHelper.queryInventory(IabHelper.java:462)
at my.package.util.iab.IabHelper$2.run(IabHelper.java:521)
at java.lang.Thread.run(Thread.java:1019)

还有一个是:

java.lang.NullPointerException
at my.package.activities.MainActivity$4.onIabSetupFinished(MainActivity.java:159)
at my.package.util.iab.IabHelper$1.onServiceConnected(IabHelper.java:242)

我的 Activity 实现遵循 Google 的示例代码(示例中所有引用的类均未触及):

IabHelper mHelper;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//...

mHelper = new IabHelper(this, IAB_PUBLIC_KEY);
mHelper.enableDebugLogging(true);

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
return;
}

// Hooray, IAB is fully set up. Now, let's get an inventory of
// stuff we own.
mHelper.queryInventoryAsync(mGotInventoryListener); //***(1)***
}
});
}

// 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()) {
if (inventory.hasPurchase(SoundsGlobals.IAB_SKU_PREMIUM)){
//we are premium, do things
}
}
else{
//oops
}
}
};

@Override
protected void onDestroy() {
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
super.onDestroy();
}

我假设这两个错误都来自标记为 ***(1)***

的行

这些错误的原因是什么?如果我只在 onIabSetupFinished 内调用 queryInventoryAsync,那么 mHelper 怎么可能为空,或者 mHelper没有设置好?

有人知道解决办法吗?

最佳答案

正如@Martin 解释的那样,Google In-App Billing 示例中存在导致此问题的错误。

但是,在修复它之后,我仍然在内部调用中收到一些错误(在 queryInventoryAsync 中创建的线程内的 queryInventory 在某些极少数情况下报告帮助程序不是设置)。在这种情况下,我通过添加一个额外的捕获解决了这个问题:

try {
inv = queryInventory(querySkuDetails, moreSkus);
}
catch (IabException ex) {
result = ex.getResult();
}
catch(IllegalStateException ex){ //ADDED THIS CATCH
result = new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Helper is not setup.");
}

我在 mHelper.dispose() 上也遇到了崩溃,我以类似的方式修复了它:

try{
if (mContext != null) mContext.unbindService(mServiceConn);
}
catch(IllegalArgumentException ex){ //ADDED THIS CATCH
//IGNORE IT - somehow, the service was already unregistered
}

当然,您可以将它们静默记录到 ACRA,而不是忽略这些错误,例如 :)

感谢您的所有评论。

关于Android 应用内结算 v3 : "Can' t perform operation: queryInventory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14026668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com