コード例 #1
0
  /*
     Buy the items - notifies of purchase success or failure
     Updates local store
  */
  public void purchaseStoreItem(Activity c, StoreItem item, PurchaseResultListener listener) {
    purchaseListener = listener;

    mHelper.flagEndAsync();
    mHelper.launchPurchaseFlow(
        c,
        item.googleSKU,
        10001,
        mPurchaseFinishedListener,
        "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
  }
コード例 #2
0
  /*
     Init method - must be called before doing any store activity
     Wait for the ready listener to return storeReady
     isStore ready can be used for manual checks
  */
  public void initialiseInAppPurchase(Context c, final PurchaseStoreReady readyListener) {
    mHelper = new IabHelper(c, PUBLIC_PURCHASE_KEY);

    mHelper.startSetup(
        new IabHelper.OnIabSetupFinishedListener() {
          public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
              isStoreReady = false;
              readyListener.storeFailed();
            } else {
              isStoreReady = true;
              readyListener.storeReady();
            }
          }
        });
  }
コード例 #3
0
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

          mHelper.flagEndAsync();

          if (result.isFailure()) {
            updateListener.updateFailed();
            return;
          }

          for (StoreItem item : getAllStoreItems(c)) {
            if (item.googleSKU != null) {
              item.isPurchased = inventory.hasPurchase(item.googleSKU);
            }
          }

          writePurchasedItems(c);

          updateListener.updateSuccess();
        }
コード例 #4
0
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
          StoreItem purchasedItem = null;
          int index = 0;

          mHelper.flagEndAsync();

          if (purchase == null) {
            Toast.makeText(
                    c,
                    "We can't find the requested item. Please try again soon!",
                    Toast.LENGTH_SHORT)
                .show();
            return;
          }

          for (StoreItem item : getAllStoreItems(c)) {
            if (item.googleSKU.compareTo(purchase.getSku()) == 0) {
              purchasedItem = item;
              break;
            }

            index++;
          }

          if (result.isFailure() || purchasedItem == null) {
            Log.d("FF PURCHASE", "Error purchasing: " + result);
            purchaseListener.purchaseFailed(purchasedItem, purchase);
            return;
          } else {
            purchasedItem.isPurchased = true;
            getAllStoreItems(c).get(index).isPurchased = true;
            purchaseListener.purchaseSuccess(purchasedItem, purchase);
          }

          writePurchasedItems(c);
        }
コード例 #5
0
 /*
    Destroy method - call on fragment/activity destroy
 */
 public void destroyInAppPurchase() {
   if (mHelper != null) mHelper.dispose();
   mHelper = null;
 }
コード例 #6
0
  /*
     Get the purchased items from Google
     Stores them locally for next time - should be called at app launch to sync with G account
  */
  public void checkPurchasedItems(PurchaseUpdateListener listener) {
    updateListener = listener;

    mHelper.queryInventoryAsync(mGotInventoryListener);
  }