且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用内结算购买后

更新时间:2022-12-31 12:10:14

如果你遵循了地下城的例子,你可能已经实施了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();