2011-12-20 113 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); 
}