2017-01-04 14 views
0

サブスクリプション付きのAndroidアプリを持っていて、ユーザーがアクティブなサブスクリプションを持っているかどうかを問い合わせるのにIabHelperを使用します。今私はまた、この定期購読が自動更新されているかどうかを知る必要があります。IabHelper:サブスクリプションが自動更新されているかどうかをチェック

私はこのようなサブスクリプションのステータスを照会しています:

private boolean userIsSubscribed() { 
    ArrayList<String> skuList = new ArrayList<>(); 
    skuList.add(PREMIUM_SUBSCRIPTION); 
    // Check the subscription status 
    try { 
     Inventory inventory = iabHelper.queryInventory(true, null, skuList); 
     Purchase purchase = inventory.getPurchase(PREMIUM_SUBSCRIPTION); 
     // Is the user subscribed? 
     if (purchase != null && purchase.getPurchaseState() == 0) { 
      // User is subscribed 
      Log.d(TAG, "Subscribed."); 
      // TODO check if subscription is auto-renewing 
      return true; 
     } else { 
      // User is not subscribed 
      Log.d(TAG, "Not subscribed."); 
      return false; 
     } 
    } catch (IabException | NullPointerException e) { 
     // There was an error with the subscription process 
     Log.e(TAG, e.getMessage(), e); 
     return false; 
    } catch (IllegalStateException e) { 
     // IabHelper not set up 
     Log.e(TAG, e.getMessage(), e); 
     return false; 
    } 
} 

Purchaseオブジェクトは、残念ながら、自動更新のフィールドを求めるための方法を持っていません。私はこの情報を得ることができる他の方法はありますか?

答えて

2

Purchase#isAutoRenewingメソッドを呼び出します。このメソッドが欠落している場合、あなたはあなたの参照IABファイルを更新する必要がある場合があります

if (purchase != null && purchase.getPurchaseState() == 0) { 
     // User is subscribed 
     Log.d(TAG, "Subscribed."); 
     if (purchase.isAutoRenewing()){ 
      return true; 
     } 

https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive/app/src/main/java/com/example/android/trivialdrivesample/util/Purchase.java

関連する問題