IabHelper PurchaseFinishedListener

如果我通过标准发送购买意向

String mySku = "android.test.purchased"; mHelper.launchPurchaseFlow(this, mySku, 10001, mPurchaseFinishedListener); 

我能够购买的项目,它将存储,我可以查询该项目,并且工作正常。 唯一不起作用的是PurchaseFinishedListener。 我已经得到了与示例应用程序非常相似的代码,但它似乎并没有被调用。

 12-12 01:40:47.248: D/IabHelper(23502): Calling getPurchases with continuation token: null 12-12 01:40:50.116: D/IabHelper(23502): Starting async operation: launchPurchaseFlow 

这是最后两个被调用的方法,在完成购买后,它不会调用purchasefinishedlistener

 IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase purchase) { Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase); if (result.isFailure()) { complain("Error purchasing: " + result); // setWaitScreen(false); return; } if (purchase.getSku().equals(mySku)) { Log.d(TAG, "mySku is being consumed."); mHelper.consumeAsync(purchase, mConsumeFinishedListener); } Log.d(TAG, "Purchase successful."); new AsyncQuestionsActivity().doInBackground(); } }; 

没有从日志到结束的作品。 有什么我只是不知何故失踪?

Solutions Collecting From Web of "IabHelper PurchaseFinishedListener"

我发现如何解决它。 在onActivityResult中实现handleActivityResult。 需要在监听者和启动的购买stream程之间build立一个桥梁。

下面给出的是我使用的代码:

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data); // Pass on the activity result to the helper for handling if (!mHelper.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data); } else { Log.d(TAG, "onActivityResult handled by IABUtil."); } } 

AndroidPenguin,我遇到了同样的问题,但是我有活动正确设置,但我purchasefinishedlistener不执行。

这是我的onActivityResult

 @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (SettingsManager.getBooleanSetting(rootId, "inapppurchase", false)){ Log.d(TAG, "take care of activity result with billing helper"); if (!mBillingService.handleActivityResult(requestCode, resultCode, data)) { // not handled, so handle it ourselves (here's where you'd // perform any handling of activity results not related to in-app // billing... super.onActivityResult(requestCode, resultCode, data); } else { Log.d(TAG, "onActivityResult handled by IABUtil."); } } else super.onActivityResult(requestCode, resultCode, data); } 

在我的情况下,它正在尝试这样,等到谷歌播放对话框closures本身。然后,监听器会被调用

对于那些遇到同样问题的人,我正在经历…

我只是让我的成员variablesIabHelper静态,并解决了这个问题。

我已经添加了AndroidPenguin的代码,并且在我购买了一个项目(所以onActivityResult从未有机会调用handleActivityResult,因为mHelper为null)之后,仍然从null IabHelper中崩溃。