PurchaseFinishedListener

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();
    }
};

从日志到最后一无所有。有什么我想念的吗?

最佳答案

我找到了解决方法。在onActivityResult中实现handleActivityResult。需要在监听器和已启动的购买流程之间建立桥梁。

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

@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.");
        }
    }

关于android - IabHelper PurchaseFinishedListener,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13831503/

10-10 07:08