2011-12-20 3 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을 구현? 코드에서 어딘가에

, 당신은, 당신이 상태를 추적 할 수있는 공유 환경 설정을 사용하여

public void onPurchaseStateChange(...) 

라는 방법을 재정의 purchaseObserver에서이

ResponseHandler.register(purchaseObserver); 

같은 PurchaseObserver를 등록 그 방법으로 앱의 취소/환불을 처리하는 것이 중요합니다. 그렇지 않다면 물건을 무료로 나눠주고있는 것입니다. 코드는 다음과 유사 할 수 있습니다.

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 –

+1

Blundell 자습서를 따르는 경우 환경 설정을 업데이트하는 코드가 mTransactionHandler 내부 클래스에 있어야합니다. . 구매 상태는 구매 (사용자는 주문에 대해 청구 됨), 취소 (서버에서 청구가 실패했습니다.) 및 환불 (구매 환불)입니다. –

+0

blundell 코드에서 "purchaseState"는 무엇으로 표시됩니까? –

0

SharedPreferences를 사용하여 구입 한 항목을 유지할 수 있습니다. 그런 다음 InAppActivity의 onCreate() 내부에서 다음을 수행하십시오.

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