2017-10-24 13 views
2

다음 코드로 구독 상태를 쿼리하고 있습니다. 이것으로이 구독에 대한 부울 상태를 얻을 수 있습니다. 이 결과는 네트워크 상태 또는 패키지 제거/재설치 또는 기타 기준에 의해 영향을 받습니까? 구독 상태를 찾는 방법은 무엇입니까? 코드의사용자의 가입 여부를 확인하는 올바른 방법은 무엇입니까?

mHelper = new IabHelper(this, PUBLIC_KEY); 
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 
public void onIabSetupFinished(IabResult result) { 
     if (! result.isSuccess()) { 
      return; 
     } 
     if (QueryInventoryListner.mHelper == null){ 
      return; 
     } 
     mHelper.queryInventoryAsync(mGotInventoryListener); 
     } 
    }); 

& 쿼리 재고 마침 리스너 비

mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 
@Override 
public void onQueryInventoryFinished(final IabResult result, final Inventory inventory) { 
    Purchase subscriptionForFullVersion = inventory.getPurchase(SKU_SUBSCRIPTION); 
    boolean isSubscribe = subscriptionForFullVersion != null ; 
     if(isSubscribe) { 
     //User is subscribed to SKU_SUBSCRIPTION 
     } 
} 

답변

1

이 예는 심지어 응용 프로그램을 다시 설치 한 후 사용할 수 있습니다.

당신은 try\catch 블록을 추가하는 것을 잊지 :

public void onIabSetupFinished(IabResult result) {  
     if (!result.isSuccess()) { 
      return; 
     } 
     if (QueryInventoryListner.mHelper == null){ 
      return; 
     } 
     try { 
      mHelper.queryInventoryAsync(mGotInventoryListener); 
     } catch (IabAsyncInProgressException e) { 
      complain(context.getResources().getString(R.string.subscription_error_subscription_error_to_query_inventory_another_async)); 
     } 
    } 

이처럼 내 mGotInventoryListener : 또한

// Listener that's called when we finish querying the items and subscriptions we own 
private QueryInventoryFinishedListener mGotInventoryListener = new QueryInventoryFinishedListener() { 
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) { 
     Logging.d(TAG, "Query inventory finished."); 

     // Have we been disposed of in the meantime? If so, quit. 
     if (mHelper == null) return; 

     // Is it a failure? 
     if (result.isFailure()) { 
      complain(context.getResources().getString(R.string.subscription_error_subscription_error_to_query_inventory) + " " + result); 
      return; 
     } 

     Logging.d(TAG, "Query inventory was successful."); 

     // First find out which subscription is auto renewing 
     Purchase subscriptionMonthly = inventory.getPurchase(SKU_SUBSRIPTION_MONTHLY); 

     // The user is subscribed if either subscription exists, even if neither is auto 
     // renewing 
     mSubscribedToFreeAds = (subscriptionMonthly != null); 
     Logging.d(TAG, "User " + (mSubscribedToFreeAds ? "HAS" : "DOES NOT HAVE") 
       + " monthly subscription."); 
     if (mSubscribedToFreeAds) { 
      putPurchase(subscriptionMonthly);//save purchase 
      isSubscribed = true; 
     } else { 
      clearPurchase(); 
      isSubscribed = false; 
     } 

     updateUi(); 
     setWaitScreen(false); 
     Logging.d(TAG, "Initial inventory query finished; enabling main UI."); 
    } 
}; 

당신이 출시되기 전에 가입을 테스트 할 수 있습니다 Setting Up for Test Purchases