コード例 #1
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
          Log.e(TAG, "Query inventory finished.");
          if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            finish();
            return;
          }

          Log.e(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().
           */
          // Check for gas delivery -- if we own gas, we should fill up the
          // tank
          // immediately
          Purchase purchase = inventory.getPurchase(item);
          if (purchase != null && verifyDeveloperPayload(purchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(item), mConsumeFinishedListener);
            return;
          }

          // Do we have the premium upgrade?
          SkuDetails item1SkuDetail = inventory.getSkuDetails(item);
          Log.e(TAG, "item1SkuDetail is " + item1SkuDetail);
          mHelper.launchPurchaseFlow(Pay.this, item, 100, mPurchaseFinishedListener);
        }
コード例 #2
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    item = getIntent().getStringExtra(PARAM_ITEM);
    // Create the helper, passing it our context and the public key to
    // verify signatures with
    Log.e(TAG, "Creating IAB helper. item:" + item);
    mHelper = new IabHelper(this, base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set
    // this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    mHelper.startSetup(
        new IabHelper.OnIabSetupFinishedListener() {
          public void onIabSetupFinished(IabResult result) {
            Log.e(TAG, "Setup finished.");
            if (!result.isSuccess()) {
              // Oh noes, there was a problem.
              complain("Problem setting up in-app billing: " + result);
              finish();
              return;
            }

            // Hooray, IAB is fully set up. Now, let's get an inventory of
            // stuff we own.
            Log.e(TAG, "Setup successful. Querying inventory.");
            ArrayList<String> additionalSkuList = new ArrayList<String>();
            additionalSkuList.add(item);
            mHelper.queryInventoryAsync(true, additionalSkuList, mGotInventoryListener);
          }
        });
  }
コード例 #3
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
 @Override
 public void onDestroy() {
   super.onDestroy();
   try {
     if (mHelper != null) mHelper.dispose();
   } catch (Exception e) {
   }
   mHelper = null;
 }
コード例 #4
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.e(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);

    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
      // not handled, so handle it ourselves (here's where you'd
      // perform any handling of activity results not related to in-app
      // billing...
      super.onActivityResult(requestCode, resultCode, data);
    } else {
      Log.e(TAG, "onActivityResult handled by IABUtil.");
    }
  }
コード例 #5
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
          Log.e(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
          if (result.isFailure()) {
            complain("Error purchasing: " + result);
            finish();
            return;
          }

          if (!verifyDeveloperPayload(purchase)) {
            complain("Error purchasing. Authenticity verification failed.");
            finish();
            return;
          }

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

          if (purchase.getSku().equals(item)) {
            // bought 1/4 tank of gas. So consume it.
            mHelper.consumeAsync(purchase, mConsumeFinishedListener);
            // bought the premium upgrade!
            Log.e(TAG, "Purchase is SKU_JieShuo_SHAIDAO. Congratulating user.");
          }
        }
コード例 #6
0
ファイル: Pay.java プロジェクト: hsoftxl/PlayProject
        public void onConsumeFinished(Purchase purchase, IabResult result) {
          Log.e(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result);

          // We know this is the "gas" sku because it's the only one we
          // consume,
          // so we don't check which sku was consumed. If you have more than
          // one
          // sku, you probably should check...
          if (result.isSuccess()) {
            // successfully consumed, so we apply the effects of the item in
            // our
            // game world's logic, which in our case means filling the gas
            // tank a bit
            Log.e(TAG, "支付成功");
            payMent.onSucess(item);
            finish();
          } else {
            Log.e(TAG, "支付失败");
            mHelper.consumeAsync(purchase, mConsumeFinishedListener);
            complain("Error while consuming: " + result);
          }
          Log.e(TAG, "End consumption flow.");
        }