Example usage for android.app PendingIntent getIntentSender

List of usage examples for android.app PendingIntent getIntentSender

Introduction

In this page you can find the example usage for android.app PendingIntent getIntentSender.

Prototype

public IntentSender getIntentSender() 

Source Link

Document

Retrieve a IntentSender object that wraps the existing sender of the PendingIntent

Usage

From source file:com.mohamnag.inappbilling.InAppBillingPlugin.java

/**
 * Buy an already loaded item.//from  w  w  w . jav a 2  s .  c o  m
 *
 * @param productId
 * @param callbackContext
 */
private void buy(final String productId, final CallbackContext callbackContext) throws JSONException {

    jsLog("buy called for productId: " + productId);

    SkuDetails product = myInventory.getSkuDetails(productId);
    if (product == null) {
        callbackContext
                .error(new Error(ERR_PRODUCT_NOT_LOADED, "Product intended to be bought has not been loaded.")
                        .toJavaScriptJSON());
    } else if (BILLING_ITEM_TYPE_SUBS.equals(product.getType()) && !subscriptionSupported) {
        callbackContext.error(new Error(ERR_SUBSCRIPTION_NOT_SUPPORTED, "Subscriptions are not supported")
                .toJavaScriptJSON());
    } else {
        cordova.setActivityResultCallback(this);
        int requestCode = REQUEST_CODE_BASE++;

        try {
            jsLog("Preparing purchase flow");

            Bundle buyIntentBundle = iabService.getBuyIntent(3, cordova.getActivity().getPackageName(),
                    product.getSku(), product.getType(), null);

            int response = buyIntentBundle.getInt("RESPONSE_CODE");
            if (response == BILLING_RESPONSE_RESULT_OK) {
                PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

                pendingPurchaseCallbacks.put(requestCode, callbackContext);

                cordova.getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode,
                        new Intent(), 0, 0, 0);

                jsLog("Purchase flow launched successfully");
            } else if (response == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                callbackContext.error(
                        new Error(ERR_PURCHASE_OWNED_ITEM, "Item requested to be bought is already owned.")
                                .toJavaScriptJSON());
            } else {
                callbackContext.error(
                        new Error(ERR_PURCHASE_FAILED, "Could not get buy intent. Response code: " + response)
                                .toJavaScriptJSON());
            }
        } catch (RemoteException ex) {
            Logger.getLogger(InAppBillingPlugin.class.getName()).log(Level.SEVERE, null, ex);
            callbackContext.error(new Error(ERR_PURCHASE_FAILED, ex.getMessage()).toJavaScriptJSON());
        } catch (IntentSender.SendIntentException ex) {
            Logger.getLogger(InAppBillingPlugin.class.getName()).log(Level.SEVERE, null, ex);
            callbackContext.error(new Error(ERR_PURCHASE_FAILED, ex.getMessage()).toJavaScriptJSON());
        }

    }
}

From source file:com.cloudzilla.fb.FacebookServiceProxy.java

public void showAdvertisement(Activity activity) throws RemoteException, SendIntentException {
    if (mFacebookService == null) {
        Log.e(TAG, "You are not connected to FacebookService");
        return;/*from  www.  ja  v  a2 s .c  om*/
    }

    PendingIntent pendingIntent = mFacebookService.getAdvertisementIntent();
    int requestCode = 0;
    Intent fillInIntent = new Intent();
    int flagsMask = 0;
    int flagsValues = 0;
    int extraFlags = 0;
    activity.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, fillInIntent, flagsMask,
            flagsValues, extraFlags);
}

From source file:com.cloudzilla.fb.FacebookServiceProxy.java

public void showOfferWall(Activity activity, String currencyId, int offerwallId)
        throws RemoteException, SendIntentException {
    if (mFacebookService == null) {
        Log.e(TAG, "You are not connected to FacebookService");
        return;/*from  w  ww  .j a va 2s .c o  m*/
    }

    PendingIntent pendingIntent = mFacebookService.getOfferWallIntent(currencyId, offerwallId);
    int requestCode = 0;
    Intent fillInIntent = new Intent();
    int flagsMask = 0;
    int flagsValues = 0;
    int extraFlags = 0;
    activity.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, fillInIntent, flagsMask,
            flagsValues, extraFlags);
}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

void startBuyFlow() {
    if (IAPService == null) {
        // TODO: res
        Toast.makeText(this, "Impossible de faire des achats sur un appareil non support par Google.",
                Toast.LENGTH_LONG).show();
        return;/*from   w w w .  j a va  2 s . c  om*/
    }

    try {
        Bundle buyIntentBundle = IAPService.getBuyIntent(3, getPackageName(), utils.SKU_DONATE, "inapp", null);
        int responseCode = (int) buyIntentBundle.get("RESPONSE_CODE");
        switch (responseCode) {
        case 0: // BILLING_RESPONSE_RESULT_OK
            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
            try {
                if (pendingIntent != null) {
                    IntentSender sender = pendingIntent.getIntentSender();
                    startIntentSenderForResult(sender, PURCHASE_REQUEST_CODE, new Intent(), 0, 0, 0);
                }
            } catch (IntentSender.SendIntentException e) {
                Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT).show();
            }
            break;
        case 1: // BILLING_RESPONSE_RESULT_USER_CANCELED
            break;
        case 3: // BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 4: // BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 5: // BILLING_RESPONSE_RESULT_DEVELOPER_ERROR
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 6: // BILLING_RESPONSE_RESULT_ERROR
            Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT);
            break;
        case 7: // BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
            PrefUtils.setUserDonated(this, true);
            Toast.makeText(mContext, R.string.toast_purchase_thanks, Toast.LENGTH_LONG).show();
            mAdView.destroy();
            LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
            adLayout.setVisibility(View.GONE);
            break;
        case 8: // BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED
            break;
        }
    } catch (RemoteException e) {
        Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.soomla.store.billing.nokia.NokiaIabHelper.java

/**
 * See parent/*from  w  ww .  j av a2  s  .  c o m*/
 */
@Override
protected void launchPurchaseFlowInner(Activity act, String sku, String extraData) {
    IabResult result;

    try {
        SoomlaUtils.LogDebug(TAG, "Constructing buy intent for " + sku + ", item type: " + ITEM_TYPE_INAPP);
        Bundle buyIntentBundle = mService.getBuyIntent(3, SoomlaApp.getAppContext().getPackageName(), sku,
                ITEM_TYPE_INAPP, extraData);
        buyIntentBundle.putString("PURCHASE_SKU", sku);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogError(TAG,
                    "Unable to buy item, Error response: " + IabResult.getResponseDesc(response));

            IabPurchase failPurchase = new IabPurchase(ITEM_TYPE_INAPP, "{\"productId\":" + sku + "}", "");
            result = new IabResult(response, "Unable to buy item");
            purchaseFailed(result, failPurchase);
            act.finish();
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        SoomlaUtils.LogDebug(TAG, "Launching buy intent for " + sku + ". Request code: " + RC_REQUEST);
        mPurchasingItemSku = sku;
        mPurchasingItemType = ITEM_TYPE_INAPP;

        act.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_REQUEST, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        SoomlaUtils.LogError(TAG, "SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        purchaseFailed(result, null);
    } catch (RemoteException e) {
        SoomlaUtils.LogError(TAG, "RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        purchaseFailed(result, null);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "Failed to generate failing purchase.");
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate failing purchase.");
        purchaseFailed(result, null);
    }

}

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * See parent//from   w  w w.j  a  v a  2  s.  co m
 */
@Override
protected void launchPurchaseFlowInner(Activity act, String sku, String extraData) {
    IabResult result;

    try {
        SoomlaUtils.LogDebug(TAG, "Constructing buy intent for " + sku + ", item type: " + ITEM_TYPE_INAPP);
        Bundle buyIntentBundle = mService.getBuyIntent(3, SoomlaApp.getAppContext().getPackageName(), sku,
                ITEM_TYPE_INAPP, extraData);
        buyIntentBundle.putString("PURCHASE_SKU", sku);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogError(TAG,
                    "Unable to buy item, Error response: " + IabResult.getResponseDesc(response));

            IabPurchase failPurchase = new IabPurchase(ITEM_TYPE_INAPP, "{\"productId\":" + sku + "}", null);
            result = new IabResult(response, "Unable to buy item");
            purchaseFailed(result, failPurchase);
            act.finish();
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        SoomlaUtils.LogDebug(TAG, "Launching buy intent for " + sku + ". Request code: " + RC_REQUEST);
        mPurchasingItemSku = sku;
        mPurchasingItemType = ITEM_TYPE_INAPP;

        act.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_REQUEST, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        SoomlaUtils.LogError(TAG, "SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        purchaseFailed(result, null);
    } catch (RemoteException e) {
        SoomlaUtils.LogError(TAG, "RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        purchaseFailed(result, null);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "Failed to generate failing purchase.");
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate failing purchase.");
        purchaseFailed(result, null);
    }

}

From source file:com.abplus.surroundcalc.billing.BillingHelper.java

public void launchPurchaseFlow(Activity activity, String sku, int requestCode,
        OnPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    asyncFlag.start("launchPurchaseFlow");
    Result result;/* www.j a  va 2s.c o  m*/

    try {
        Bundle buyIntentBundle = connection.getBuyIntent(sku, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            result = new Result(response, "Unable to buy item");
            if (listener != null)
                listener.onPurchaseFinished(result, null);
        } else {
            PendingIntent intent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
            this.requestCode = requestCode;
            purchaseListener = listener;
            activity.startIntentSenderForResult(intent.getIntentSender(), requestCode, new Intent(), 0, 0, 0);
        }
    } catch (IntentSender.SendIntentException e) {
        result = new Result(HELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    } catch (RemoteException e) {
        result = new Result(HELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    }
}

From source file:org.kontalk.billing.GoogleBillingService.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity./*from  w  w w.  ja  v a2  s  .  c o m*/
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
        OnPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    startAsyncOperation("launchPurchaseFlow");
    BillingResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        BillingResult r = new BillingResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
                "Subscriptions are not available.");
        endAsyncOperation();
        if (listener != null)
            listener.onPurchaseFinished(r, null);
        return;
    }

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            endAsyncOperation();
            result = new BillingResult(response, "Unable to buy item");
            if (listener != null)
                listener.onPurchaseFinished(result, null);
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        endAsyncOperation();

        result = new BillingResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        endAsyncOperation();

        result = new BillingResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    }
}

From source file:com.evolup.test.IAPTest01.util.IabHelper.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity./*from w w  w  .  ja va2 s  .co m*/
 * @param sku The sku of the item to purchase.
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    try {
        logDebug("Constructing buy intent for " + sku);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, ITEM_TYPE_INAPP,
                extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));

            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    }
}

From source file:com.yourkey.billing.util.InAppBilling.java

private void serviceConnected(IBinder service) {
    // get service pointer
    inAppBillingService = IInAppBillingService.Stub.asInterface(service);

    // make sure billing is supported for itemType (one-time or subscription)
    try {//from  w w w .  j  av a2  s. c o m
        // check for in-app billing v3 support
        int result = inAppBillingService.isBillingSupported(IN_APP_BILLING_API_VERSION, packageName, itemType);
        if (result != RESULT_OK) {
            // unbind service
            dispose();

            // call purchase listener with error message
            inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_PURCHASE_NOT_SUPPORTED, result));
            return;
        }
    }

    // system exception executing isBillingSupported method
    catch (Exception e) {
        // unbind service
        dispose();

        // call purchase listener with error message
        inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_PURCHASE_NOT_SUPPORTED, e));
        return;
    }

    // test to make sure item sku is valid
    String resultMsg = testItemSku();
    if (resultMsg != null) {
        // unbind service
        dispose();

        // call purchase listener with error message
        inAppBillingListener.inAppBillingFailure(resultMsg);
        return;
    }

    // Get all items owned by this user for this application
    // and test if user already owns this item.
    // If we are in consume mode and item is owned, consume the item

    /*   
       resultMsg = testItemOwned();
       if(!resultMsg.equals(RESULT_TEXT_ITEM_ALREADY_OWNED) && !resultMsg.equals(RESULT_TEXT_ITEM_NOT_OWNED))
          {
          // unbind service
           dispose();
            
           // call purchase listener with error message
          inAppBillingListener.inAppBillingFailure(resultMsg);
          return;
          }
            
       // user owns this item
       if(resultMsg.equals(RESULT_TEXT_ITEM_ALREADY_OWNED))
          {
          // unbind service
           dispose();
            
           // for consume mode
           if(consumeActivity)
             inAppBillingListener.inAppBillingConsumeSuccsess();
                   
           // for buy mode 
           else
             inAppBillingListener.inAppBillingItemAlreadyOwned();
                   
           // exit
          return;
          }*/

    // consume and user does not own this item
    if (consumeActivity) {
        // unbind service
        dispose();

        // call listener
        inAppBillingListener.inAppBillingItemNotOwned();
        return;
    }

    try {
        // build intent bundle for the purpose of purchase itemSku
        Bundle buyIntentBundle = inAppBillingService.getBuyIntent(IN_APP_BILLING_API_VERSION, packageName,
                itemSku, itemType, PURCHASE_EXTRA_DATA);

        // buyIntentBundle has two key value pairs
        // RESPONSE_CODE with standard response code
        // BUY_INTENT with PendingIntent to start the purchase flow
        int buyResult = getResponseCodeFromBundle(buyIntentBundle);
        if (buyResult != RESULT_OK) {
            // unbind service
            dispose();

            // error message
            inAppBillingListener
                    .inAppBillingFailure(errorMessage(PLAY_STORE_PURCHASE_FAILED + resultMessage(buyResult)));
            return;
        }

        // send Google Play Store request to purchase itemSku
        // when the purchase process is completed, the system will call onActivityResult method in parent activity
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        parentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), purchaseRequestCode,
                new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    }

    // trap exceptions
    catch (Exception e) {
        // unbind service
        dispose();

        // error message
        inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_PURCHASE_FAILED, e));
        return;
    }

    // exit
    return;
}