onIabPurchaseFinished从未叫过。
我一直在尝试为我的第一个应用设置应用内结算,并且一直在使用android.test.purchased sku。 购买通过,我设法把SKU存入我的库存,但正如标题所说,在IabPurchaseFinished,从来没有被称为。
我认为这可能与这个日志有关:“无法保存哪个视图具有焦点,因为焦点视图com.android.internal.policy.impl.PhoneWindow$DecorView@406743d0没有ID”。 popup之前,就在Google Play之前。 我不确定这是什么意思,但…
启动购买:
mHelper.launchPurchaseFlow(this, sku, 10001, mPurchaseFinishedListener, "");
听众:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase info) { System.out.println("Purchase Finish heard something"); if (result.isFailure()) { Log.d(TAG, "Error purchasing: " + result); return; } else{ Log.d(TAG,"Success!"); } } };
尝试添加到调用mHelper.launchPurchaseFlow(..)
的活动:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data); // Pass on the activity result to the helper for handling if (!mHelper.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."); } }
我刚刚发现了另一件重要的事情:用于启动购买stream程的requestCode必须> = 0!
我用“新随机()。nextInt()”生成一个随机requestCode,有时它的工作,有时它没有。 现在我发现在下面的文档中,requestCode不应该是一个负数: