Android 应用内购买消费品

标签 android in-app-purchase in-app-billing

我在我的应用程序中实现了应用内购买,我的产品类型是托管的,我使用的是 API 版本 3。 当我用我的信用卡购买时,它已成功完成。 但问题是,如果我卸载我的应用程序并想用同一个帐户购买它,它会再次向我收费吗? 根据谷歌管理产品类型的规则,我们只购买一次产品?但是为什么会这样呢? 有人帮我吗? 这是我的 PurchaseActivity.java 类

public abstract class PurchaseActivity extends BlundellActivity implements OnIabSetupFinishedListener, OnIabPurchaseFinishedListener {

    private IabHelper billingHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_purchase);
        setResult(RESULT_CANCELED);

        billingHelper = new IabHelper(this, AppProperties.BASE_64_KEY);
        billingHelper.startSetup(this);
    }

    @Override
    public void onIabSetupFinished(IabResult result) {
        if (result.isSuccess()) {
            Log.d("In-app Billing set up" + result);
            dealWithIabSetupSuccess();
        } else {
            Log.d("Problem setting up In-app Billing: " + result);
            dealWithIabSetupFailure();
        }
    }

    protected abstract void dealWithIabSetupSuccess();

    protected abstract void dealWithIabSetupFailure();

    protected void purchaseItem(String sku) {
        billingHelper.launchPurchaseFlow(this, sku, 123, this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        billingHelper.handleActivityResult(requestCode, resultCode, data);
    }


     */
    @Override
    public void onIabPurchaseFinished(IabResult result, Purchase info) {
        if (result.isFailure()) {
            dealWithPurchaseFailed(result);
        } else if (pmg.SKU.equals(info.getSku())) {
            dealWithPurchaseSuccess(result, info);
        }
        finish();
    }

    protected void dealWithPurchaseFailed(IabResult result) {
        Log.d("Error purchasing: " + result);
    }

    protected void dealWithPurchaseSuccess(IabResult result, Purchase info) {
        Log.d("Item purchased: " + result);
        // DEBUG XXX
        // We consume the item straight away so we can test multiple purchases
        billingHelper.consumeAsync(info, null);
        // END DEBUG
    }

    @Override
    protected void onDestroy() {
        disposeBillingHelper();
        super.onDestroy();
    }

    private void disposeBillingHelper() {
        if (billingHelper != null) {
            billingHelper.dispose();
        }
        billingHelper = null;
    }
}

最佳答案

这按预期工作 - 在您的代码中,您立即消费应用内购买,这意味着您可以再次购买:

protected void dealWithPurchaseSuccess(IabResult result, Purchase info) {
    Log.d("Item purchased: " + result);
    // DEBUG XXX
    // We consume the item straight away so we can test multiple purchases
    billingHelper.consumeAsync(info, null);
    // END DEBUG
}

没有任何规定说您不能多次购买受管理的产品。您不能做的是在之前购买的同一托管商品被消费之前购买托管商品。所以这完全按预期工作,如果您删除对 consumeAsync 的调用,您会发现您无法再次购买它。

示例用例:

想象一下您可以购买额外生命的游戏。首先,用户会购买额外的生命(在应用程序产品中管理),然后您的游戏(客户端或服务器)会将这些生命添加到用户的个人资料中,假设成功,您会告诉 Google Play购买已被消费。

这对于处理错误情况很重要 - 例如,假设用户的设备在初始购买和为用户的个人资料添加生命之间死机。然后,您的应用程序可以在下次启动时再次尝试添加这些生命,并在成功时消费购买。而且,很明显,您不希望用户在您成功授予之前尝试购买更多生命 - 这就是为什么您不能在消费之前购买被管理产品两次。

关于Android 应用内购买消费品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452622/

相关文章:

android - RemoteServiceException : Bad notification for startForeground: java. util.ConcurrentModificationException

android - 如何使用 ItemTouchHelper 和光标实现拖放

c# - 在实现Soomla Unity3d插件的同时进行购买时,Google播放错误

android - google android 应用内购买测试问题

android - 如何在服务器端验证 Android 应用的购买(应用计费 v3 中的谷歌播放)

java - Android:seekbar.setProgress() 给出 Nullpointer 异常

java - 将副本添加到您的应用程序中

iPhone 应用内购买用于慈善捐赠

ios - 我将如何为 SKPaymentQueue 使用未弃用的 API?

android - 在应用程序购买中尝试测试时,您请求的项目无法购买