Пример #1
0
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
          Log.d(TAG, "Query inventory finished.");
          if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
          }

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

          /*
           * Check for items we own. Notice that for each purchase, we check
           * the developer payload to see if it's correct! See
           * verifyDeveloperPayload().
           */

          // Do we have the premium upgrade?
          Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
          mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
          Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));

          // Do we have the infinite gas plan?
          Purchase infiniteGasPurchase = inventory.getPurchase(SKU_INFINITE_GAS);
          mSubscribedToInfiniteGas =
              (infiniteGasPurchase != null && verifyDeveloperPayload(infiniteGasPurchase));
          Log.d(
              TAG,
              "User "
                  + (mSubscribedToInfiniteGas ? "HAS" : "DOES NOT HAVE")
                  + " infinite gas subscription.");
          if (mSubscribedToInfiniteGas) mTank = TANK_MAX;

          // Check for gas delivery -- if we own gas, we should fill up the tank immediately
          Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
          if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
            return;
          }

          updateUi();
          setWaitScreen(false);
          Log.d(TAG, "Initial inventory query finished; enabling main UI.");
        }
Пример #2
0
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
          Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
          if (result.isFailure()) {
            complain("Error purchasing: " + result);
            setWaitScreen(false);
            return;
          }
          if (!verifyDeveloperPayload(purchase)) {
            complain("Error purchasing. Authenticity verification failed.");
            setWaitScreen(false);
            return;
          }

          Log.d(TAG, "Purchase successful.");

          if (purchase.getSku().equals(SKU_GAS)) {
            // bought 1/4 tank of gas. So consume it.
            Log.d(TAG, "Purchase is gas. Starting gas consumption.");
            mHelper.consumeAsync(purchase, mConsumeFinishedListener);
          } else if (purchase.getSku().equals(SKU_PREMIUM)) {
            // bought the premium upgrade!
            Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
            alert("Thank you for upgrading to premium!");
            mIsPremium = true;
            updateUi();
            setWaitScreen(false);
          } else if (purchase.getSku().equals(SKU_INFINITE_GAS)) {
            // bought the infinite gas subscription
            Log.d(TAG, "Infinite gas subscription purchased.");
            alert("Thank you for subscribing to infinite gas!");
            mSubscribedToInfiniteGas = true;
            mTank = TANK_MAX;
            updateUi();
            setWaitScreen(false);
          }
        }