根据开发人员站点上的文档,我最近在我的应用程序中实现了InAppBilling v3.我使用了TRIVIAL DRIVE示例中提供的utils包中的类.
我面临的问题是,如果用户已在另一台设备上再次启动购买流程时已经购买了应用程序内产品,则播放商店对话框显示ITEM ALREADY OWNED,但IabResult返回的响应代码与常量IabHelper.BILliNG_RESPONSE_RESulT_ITEM_ALREADY_OWNED不匹配.返回的响应代码实际上是IabHelper类中的错误代码之一(-1005用户已取消).
我真的很想知道如何获取实际的响应代码而不是错误代码.任何帮助,将不胜感激.
下面是回调的代码
// Callback for when a purchase is finishedIabHelper.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结果代码,无论原因为何,用户取消(-1005)都可以修复IabResult固定的所有情况下的问题.因此,为了获得正确的实际响应代码,请在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全部内容,希望文章能够帮你解决android-InAppBilling v3 IabResult响应代码BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)