0

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



    };     
};
4

2 回答 2

3

如果您遵循 Dungeons 示例,您可能已经实现了 ResponsHandler/PurchaseObserver ?

在您的代码中的某处,您已经像这样注册了 PurchaseObserver

ResponseHandler.register(purchaseObserver); 

在 purchaseObserver 中,您覆盖调用的方法

public void onPurchaseStateChange(...)

通过使用共享首选项,您可以在该方法中跟踪应用程序的状态。处理取消/退款很重要。如果没有,您将免费赠送您的东西。代码可能看起来像这样

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();
于 2011-12-20T06:10:58.663 回答
0

您可以使用 SharedPreferences 来持久化购买的商品。然后在 InAppActivity 的 onCreate() 中,执行以下操作:

if(settings.getBoolean("isAwesomeItemBought") {
   buyButton.setVisibility(View.GONE);
   buyText.setVisibility(View.VISIBLE);
}
于 2011-12-20T06:15:11.553 回答