gpt4 book ai didi

android - InAppBilling v3 IabResult 响应代码 BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:59 25 4
gpt4 key购买 nike

根据开发者网站上的文档,我最近在我的应用程序中实现了 InAppBilling v3。我使用了 TRIVIAL DRIVE 示例中提供的 utils 包中的类。

我面临的问题是,如果用户已经在另一台设备上再次启动购买流程时购买了应用内产品,Play 商店对话框会显示 ITEM ALREADY OWNEDIabResult 与常量 IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED 不匹配。返回的响应代码实际上是 IabHelper 类中的错误代码之一(-1005 用户已取消)。

我真的很想知道如何获得实际的响应代码而不是错误代码。任何帮助,将不胜感激。

回调代码如下

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

if (result.isFailure()) {
if (result.getResponse() ==
IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
//already owned
boolean isPremium = true;
SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
//setWaitScreen(false);
return;
}
//handle error
complain(result.getResponse() + " " + "Error purchasing: " + result);
//setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
//corrupted
complain("Error purchasing. Authenticity verification failed.");
//setWaitScreen(false);
return;
}

//successful
if (purchase.getSku().equals(NO_ADS_PRODUCT_ID)) {
// bought the premium upgrade!
alert("Thank you for upgrading to premium!");
boolean isPremium = true;
SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
//setWaitScreen(false);
}
}
};

最佳答案

我终于设法在 IabHelper 代码中找到了问题,所以只要在 handleActivityResult 中返回 Activity.RESULT_CANCELED 结果代码,它就会出现> 所有此类情况的 IabResult 方法都已通过 用户取消 (-1005) 修复,无论原因是什么。因此,为了获得正确的实际响应代码,请在 handleActivityResult

中替换以下代码
 else if (resultCode == Activity.RESULT_CANCELED) {
logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
}

有了这个

 else if (resultCode == Activity.RESULT_CANCELED) {
logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
result = new IabResult(responseCode, null);
if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
}

希望它能节省一些人的时间

关于android - InAppBilling v3 IabResult 响应代码 BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31533335/

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