应用内结算错误:无法购买商品,错误回复:7:商品已经拥有

时间:2014-04-10 11:19:56

标签: android

我是使用应用内结算方式开发应用的新手,我已经对其进行了一些实施 它给我以下错误  应用内结算错误:无法购买商品,错误回复:7:商品已经拥有 给我解决方案

2 个答案:

答案 0 :(得分:2)

在再次购买之前,您需要先消耗一件物品。

IabHelper mHelper = new IabHelper(ACTIVITY, base64EncodedPublicKey);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent 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.");
    }
}

答案 1 :(得分:1)

作为Android Developer site中给出的示例项目 命名为TrivialDrive,我们可以按照以下方式使用购买的物品......

    // Check for gas delivery -- if we own gas, we should fill up the tank immediately
    Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
    if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
        Log.d(TAG, "We have gas. Consuming it.");
        mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
        return;
    }

// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
    public void onConsumeFinished(Purchase purchase, IabResult result) {
        Log.d(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result);

        // if we were disposed of in the meantime, quit.
        if (mHelper == null) return;

        // We know this is the "gas" sku because it's the only one we consume,
        // so we don't check which sku was consumed. If you have more than one
        // sku, you probably should check...
        if (result.isSuccess()) {
            // successfully consumed, so we apply the effects of the item in our
            // game world's logic, which in our case means filling the gas tank a bit
            Log.d(TAG, "Consumption successful. Provisioning.");
            mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
            saveData();
            alert("You filled 1/4 tank. Your tank is now " + String.valueOf(mTank) + "/4 full!");
        }
        else {
            complain("Error while consuming: " + result);
        }
        updateUi();
        setWaitScreen(false);
        Log.d(TAG, "End consumption flow.");
    }
};

希望!!!它帮助你。您可以浏览此示例项目。