コード例 #1
0
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
      billingService = IInAppBillingService.Stub.asInterface(service);
      String packageName = context.getPackageName();
      try {
        // check for in-app billing v3 support
        int response = billingService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP);
        if (response != BILLING_RESPONSE_RESULT_OK) {
          if (listener != null) {
            listener.onSetupFinished(
                new Result(response, "Error checking for billing v3 support."));
          }
          return;
        }
      } catch (RemoteException e) {
        if (listener != null) {
          listener.onSetupFinished(
              new Result(
                  HELPER_REMOTE_EXCEPTION, "RemoteException while setting up in-app billing."));
        }
        e.printStackTrace();
        return;
      }

      if (listener != null) {
        listener.onSetupFinished(new Result(BILLING_RESPONSE_RESULT_OK, "Setup successful."));
      }
    }
コード例 #2
0
  /**
   * Starts the setup process. This will start up the setup process asynchronously. You will be
   * notified through the listener when the setup process is complete. This method is safe to call
   * from a UI thread.
   *
   * @param listener The listener to notify when the setup process is complete.
   */
  public void startSetup(final OnSetupFinishedListener listener) {
    if (connection == null) {
      connection = new Connection(listener);
      Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");

      if (!context.getPackageManager().queryIntentServices(intent, 0).isEmpty()) {
        context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
      } else if (listener != null) {
        String message = context.getString(R.string.billing_service_unavailable);
        Result result = new Result(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE, message);
        listener.onSetupFinished(result);
      }
    }
  }