title: Google InAppBilling Subscription verification on app login
body: <p>I set up a subscription product in my app and it works for purchasing. I see the purchase in the google developer console. When I logged out and then back in to the app, I am taken to the subscribe page again. The app does not recognize that the subscription was purchased and it should allow the user access. If I click the subscribe button again, it does say "You've already subscribed to... Manage Subscriptions." I am not sure what needs to be done to make it either send the user to the subscribed info after verifying the subscription, or reject if subscription not found and send user to the subscribe page. I think I just don't have the knowledge yet to be sure how to build it. Here is the code I have. Am I missing a chunk of code that would handle that? </p>
  
  <p>I am using firebase as my backend for register/login. Not sure if I need to utilize firebase to keep the token, etc. Any help would be appreciated. I know I am a novice and learning, but my project is 98% complete and this is holding me back.</p>
  
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  
  import com.iliprivateequity.btfxforexalerts.Util.IabHelper;
  import com.iliprivateequity.btfxforexalerts.Util.IabResult;
  import com.iliprivateequity.btfxforexalerts.Util.Inventory;
  import com.iliprivateequity.btfxforexalerts.Util.Purchase;
  
  public class GoogleInAppBilling extends AppCompatActivity implements View.OnClickListener {
  
      private String base64EncodedPublicKey = "*****";
  
      public Button buttonSubscribe;
      public Button buttonSubscribed;
      IabHelper mHelper;
      static final String SKU_SUBSCRIBE_BTFX = "btfx_alerts_service_50";
      static final String TAG = "BTFX_Alerts";
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_google_in_app_billing);
  
          loadInAppPurchase();
  
          buttonSubscribe = (Button) findViewById(R.id.buttonsubscribe);
          buttonSubscribed = (Button) findViewById(R.id.button_subscribed);
          buttonSubscribed.setEnabled(false); //todo remember to set back to false. its true just for testing the build
  
          buttonSubscribe.setOnClickListener(this);
          buttonSubscribed.setOnClickListener(this);
  
      }
  
      private void loadInAppPurchase() {
          mHelper = new IabHelper(this, base64EncodedPublicKey);
          mHelper.enableDebugLogging(true);
  
          mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
  
              @Override
              public void onIabSetupFinished(IabResult result) {
                  if (!result.isSuccess()) {
                      Log.d(TAG, "Problem setting up in-app billing: " + result);
                  } else {
                      Log.d(TAG, "Setup successful. Querying inventory.");
                  }
                  mHelper.queryInventoryAsync(mGotInventoryListener);
              }
  
  
          });
      }
  
      IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
  
          @Override
          public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
              Log.d(TAG, "Query inventory finished.");
              if (result.isFailure()) {
                  Log.d(TAG, "Failed to query inventory: " + result);
                  return;
  
              }
              Log.d(TAG, "Query inventory was successful.");
  
              Purchase sku_purchase = inventory.getPurchase(SKU_SUBSCRIBE_BTFX);
              if (sku_purchase != null) {
                  mHelper.consumeAsync(inventory.getPurchase(SKU_SUBSCRIBE_BTFX),
                          mConsumeFinishedListener);
                  return;
  
              }
          }
      };
  
      IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener(){
          public void  onConsumeFinished(Purchase purchase, IabResult result) {
              Log.d("Tag", "Consumption finished. Purchase: " + purchase + ", result: " + result);
  
              if (mHelper == null)
                  return;
  
              if (result.isSuccess()) {
                  Log.d("TAG", "Consumption successful. Provisioning.");
              } else {
                  Log.d("TAG", "Error while consuming: " + result);
              }
              Log.d("Tag", "End consumption flow.");
          }
      };
  
      @Override
      public void onClick(View v) {
          if (v == buttonSubscribe) {
              mHelper.launchPurchaseFlow(GoogleInAppBilling.this, SKU_SUBSCRIBE_BTFX, IabHelper.ITEM_TYPE_SUBS
                      , 10001, mPurchaseFinishedListener, "alertservicepurchased");
          }
          if (v == buttonSubscribed ){
              startActivity(new Intent(this, ProfileActivity.class));
          }
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data)
      {
          if (!mHelper.handleActivityResult(requestCode, resultCode, data)){
              super.onActivityResult(requestCode,resultCode,data);
          }else{
              Log.d("TAG", "onActivityResult handled by IABUtil.");
          }
      }
  
      // Callback for when a purchase is finished
      IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
              = new IabHelper.OnIabPurchaseFinishedListener() {
          public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
              Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
  
              if (mHelper == null) return;
  
              if (result.isFailure()) {
                  Log.d(TAG, "Error purchasing: " + result);
                  return;
  
              }
              Log.d(TAG, "BTFX Alerts subscription purchased.");
              if (purchase.getSku().equals(SKU_SUBSCRIBE_BTFX)) {
                  Log.d("TAG", "Thank you for subscribing!");
                  mHelper.consumeAsync(purchase, mConsumeFinishedListener);
                  // bought the btfx alerts subscription
  
                  buttonSubscribe.setEnabled(false);
                  buttonSubscribed.setEnabled(true);
  
              }
  
          }
      };
  };
  </code></pre>