IabHelper.OnIabPurchaseFinishedListener未在应用内购买订阅v3中调用

时间:2014-11-03 04:30:15

标签: android android-fragments in-app-purchase fragment in-app-billing

当我的订阅购买结束时,我想回到IabHelper.OnIabPurchaseFinishedListener,但问题是购买完成后它没有打电话。

我曾尝试过onactivity结果,但仍然无法正常工作 这是我的代码块 我正在扩展片段,如下所示

public class ConfirmationScreen extends Fragment {

mHelper = new IabHelper(getActivity(), base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        Log.d(TAG, "Setup finished.");

        if (!result.isSuccess()) {
           // Oh noes, there was a problem.
           complain("Problem setting up in-app billing: " + result);
           return;
        }

        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        // IAB is fully set up. Now, let's get an inventory of stuff we own.
        Log.d(TAG, "Setup successful. Querying inventory.");
        //  mHelper.queryInventoryAsync(mGotInventoryListener);
    }
});

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        Log.d(TAG, "Query inventory finished.");
        // Have we been disposed of in the meantime? If so, quit.
        if (mHelper == null) return;

        // Is it a failure?
        if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
        }
        Log.d(TAG, "Query inventory was successful.");

        /*
         * Check for items we own. Notice that for each purchase, we check
         * the developer payload to see if it's correct! See
         * verifyDeveloperPayload().
         */

        Purchase gasPurchase = inventory.getPurchase(SKU);
        if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(SKU), mConsumeFinishedListener);
            return;
        }
    }
};

//Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
        // if we were disposed of in the meantime, quit.
        if (mHelper == null) return;
        Log.d(TAG, "Purchase successful.");
        if (purchase.getSku().equals(SKU)) {
            //bought 1/4 tank of gas. So consume it.
            Log.d(TAG, "Purchase is gas. Starting gas consumption.");
        }
    }
};

我已提到this链接

2 个答案:

答案 0 :(得分:4)

您需要在onActivityResult

上实施FragmentActivity方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent 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.");
    }
}

答案 1 :(得分:0)

  

您需要在FragmentActivity上实现onActivityResult方法

这必须放在活动中,实际上运行:

mHelper.launchPurchaseFlow(...);