Android inapp购买消费产品 [英] Android inapp purchasing consume able product

查看:123
本文介绍了Android inapp购买消费产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have implemented in-app purchased in my application and my product type is Managed and i am using API version 3. When i make purchase from my credit card it is successfully done. But the problem is if i uninstall my application and want to purchase this with same account it will charge me again? According to Google rules of managed product type we only purchase the product once? But why is this happening ? any one help me please? here is my PurchaseActivity.java class

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


推荐答案

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

This is working as intended - in your code you are consuming the in-app purchase immediately, which means you can then purchase it again:

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 ,您将看到无法再次购买。

There's nothing that says you can't purchase a managed product more than once. What you can't do is purchase a managed product before a previous purchase of the same managed item has been consumed. So this is working exactly as intended, and if you remove that call to consumeAsync, you'll see that you can't purchase it again.

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

Imagine some game where you can purchase extra lives. First, the user would purchase the extra lives (a managed in app product), your game (client or server) would then add those lives to the user's profile, for example, and assuming that was successful, you'd tell Google Play that the purchase has been consumed.

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

This is important in order to handle error cases - for example say the user's device dies in between the initial purchase and the addition of lives to the user's profile. Your app can then, the next time it's launched, try again to add those lives, and consume the purchase on success. And, obviously you wouldn't want the user trying to purchase even more lives before you successfully grant them - which is why you can't purchase a managed product twice before it's been consumed.

这篇关于Android inapp购买消费产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆