应用内结算购买后 [英] In-App Billing After Purchase

查看:187
本文介绍了应用内结算购买后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我怎么会能有我的应用程序中删除的按钮购买用户已购买的应用程序内结算的项目。我可以使用共享preferences,但我将如何去这样做。这是我使用的教程:的http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html.

感谢

 公开处理程序mTransactionHandler =新的处理程序(){
    公共无效的handleMessage(android.os.Message MSG){
            Log.i(TAG,交易完成);
            Log.i(TAG,交易状态:+ BillingHelper.latestPurchase.purchaseState);
            Log.i(TAG项目试图购买的是:+ BillingHelper.latestPurchase.productId);    };
};


解决方案

如果你遵循了地下城的例子,你可能已经实施了ResponsHandler / PurchaseObserver?

在某处,code,你已经注册这样的PurchaseObserver

  ResponseHandler.register(purchaseObserver);

在purchaseObserver,你重写调用的方法

 公共无效onPurchaseStateChange(...)

通过使用共享preferences您可以跟踪在该方法您的应用程序的状态。它处理取消/退款是非常重要的。如果没有,你给你的东西免费奉送。在code可能是这个样子

 共享preferences P = preferenceManager.getDefaultShared preferences(背景);
共享preferences.Editor E = p.edit();
如果(purchaseState == Consts.PurchaseState.CANCELED
         || purchaseState == Consts.PurchaseState.REFUNDED){
      e.putBoolean(采购,FALSE);
}否则如果(purchaseState == Consts.PurchaseState.PURCHASED){
      e.putBoolean(采购,真正的);
}
e.commit();

I was wondering how I would be able to have my app remove the buttons for buying an item that a user has purchased in in-app billing. I could use sharedpreferences, but how would I go about doing that. This is the tutorial I used: http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html.

Thanks

public Handler mTransactionHandler = new Handler(){
    public void handleMessage(android.os.Message msg) {
            Log.i(TAG, "Transaction complete");
            Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
            Log.i(TAG, "Item attempted purchase is: "+BillingHelper.latestPurchase.productId);



    };     
};

解决方案

If you followed the Dungeons example, you probably have implemented a ResponsHandler/PurchaseObserver ?

Somewhere in your code, you have registered a PurchaseObserver like this

ResponseHandler.register(purchaseObserver); 

In the purchaseObserver, you override the method called

public void onPurchaseStateChange(...)

By using shared preferences you can keep track of the state of your app in that method. It is important to handle cancellations/refunds. If not, you're giving your stuff away for free. The code might look something like this

SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor e = p.edit();
if (purchaseState == Consts.PurchaseState.CANCELED 
         || purchaseState ==   Consts.PurchaseState.REFUNDED) {
      e.putBoolean("PURCHASED", false);
} else if (purchaseState == Consts.PurchaseState.PURCHASED) {
      e.putBoolean("PURCHASED", true);
}
e.commit();

这篇关于应用内结算购买后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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