2011-12-20 69 views
0

我想知道如何让我的应用删除购买用户在应用内结算中购买的商品的按钮。我可以使用sharedpreferences,但我怎么去做这件事。这是我使用的教程:http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html购买后的应用内结算

感谢

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



    };  
}; 

回答

3

如果你遵循了地牢例如,你可能已经实现了ResponsHandler/PurchaseObserver?

在你的代码

某处,你已经注册这样

ResponseHandler.register(purchaseObserver); 

在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(); 
+0

这可能是一个愚蠢的问题,但purchaseState会是什么?我正在使用Blundell提供的教程。 http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html – 2011-12-20 07:23:54

+1

当遵循Blundell教程时,它看起来像你的代码来更新你的偏好应该在mTransactionHandler内部类。购买状态为已购买(用户根据订单收费),取消(服务器上的收费失败)和退款(您退还了购买)。 – 2011-12-20 16:26:48

+0

在blundell代码中,“purchaseState”代表什么? – 2012-01-02 06:07:08

0

您可以使用SharedPreferences坚持了购买的物品。然后在您的InAppActivity的onCreate()中,执行此操作:

if(settings.getBoolean("isAwesomeItemBought") { 
    buyButton.setVisibility(View.GONE); 
    buyText.setVisibility(View.VISIBLE); 
}