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:de.geithonline.abattlwp.billinghelper.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./*from   w w w . jav a 2s  . c  om*/
 * 
 * @param act
 *            The calling activity.
 * @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(final Activity act, final String sku, final String itemType,
        final int requestCode, final OnIabPurchaseFinishedListener listener, final String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        final IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
                "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null) {
            listener.onIabPurchaseFinished(r, null);
        }
        return;
    }

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

        final 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 (final SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

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

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

From source file:org.onepf.oms.appstore.googleUtils.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.
 * @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.
 *///from   www .j a v a2  s .c om
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        if (mService == null) {
            logError("Unable to buy item, Error response: service is not connected.");
            result = new IabResult(BILLING_RESPONSE_RESULT_ERROR, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            flagEndAsync();
            return;
        }
        Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, itemType, 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);
            flagEndAsync();
            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();

        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);
    }
    flagEndAsync();
}

From source file:com.android.trivialdrivesample.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  ww  w.j a  va  2 s  .  c om
 * @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 oldSkus A list of SKUs which the new SKU is replacing or null if there are none
 * @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, List<String> oldSkus, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) throws IabAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                IabResult r = new IabResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onIabPurchaseFinished(r, null);
                return;
            }
            buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldSkus, sku,
                    itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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();
        flagEndAsync();

        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();
        flagEndAsync();

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

From source file:ezturner.limitvolume.billing.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.  j  a v a  2 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 oldSkus A list of SKUs which the new SKU is replacing or null if there are none
 * @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, List<String> oldSkus, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) throws IabAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = null;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                IabResult r = new IabResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onIabPurchaseFinished(r, null);
                return;
            }
            // TODO : investigate
            //buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(),
            //        oldSkus, sku, itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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();
        flagEndAsync();

        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();
        flagEndAsync();

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

From source file:com.SoftwareOverflow.CookingScheduler.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  www  . j  ava 2  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 oldSkus A list of SKUs which the new SKU is replacing or null if there are none
 * @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, List<String> oldSkus, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) throws IabAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                IabResult r = new IabResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onIabPurchaseFinished(r, null);
                return;
            }
            buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldSkus, sku,
                    itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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));

        flagEndAsync();
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        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();
        flagEndAsync();

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

From source file:com.mental.application.utility.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 frag        The calling fragment.
 * @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)//from w  w w  .j a v  a  2  s. co m
 * @param oldSkus     A list of SKUs which the new SKU is replacing or null if there are none
 * @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(Fragment frag, String sku, String itemType, List<String> oldSkus,
        int requestCode, OnIabPurchaseFinishedListener listener, String extraData)
        throws IabAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                IabResult r = new IabResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onIabPurchaseFinished(r, null);
                return;
            }
            buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldSkus, sku,
                    itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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;
        frag.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), null);
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        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();
        flagEndAsync();

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

From source file:com.dolphingame.googleplay.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.// w ww  . j a  v  a  2s  .  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 oldSkus A list of SKUs which the new SKU is replacing or null if there are none
 * @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, List<String> oldSkus, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) throws IabAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                IabResult r = new IabResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onIabPurchaseFinished(r, null);
                return;
            }
            buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldSkus, sku,
                    itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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();
        flagEndAsync();

        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();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (Exception e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

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

From source file:com.segma.trim.InAppBillingUtilities.InAppBillingHelper.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 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  ww.java2  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 oldSkus A list of SKUs which the new SKU is replacing or null if there are none
 * @param requestCode A request code (to differentiate from other responses -- as in
 *      {@link 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, List<String> oldSkus, int requestCode,
        OnInAppBillingPurchaseFinishedListener listener, String extraData)
        throws InAppBillingAsyncInProgressException {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    InAppBillingResult result;

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

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle;
        if (oldSkus == null || oldSkus.isEmpty()) {
            // Purchasing a new item or subscription re-signup
            buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        } else {
            // Subscription upgrade/downgrade
            if (!mSubscriptionUpdateSupported) {
                InAppBillingResult r = new InAppBillingResult(IABHELPER_SUBSCRIPTION_UPDATE_NOT_AVAILABLE,
                        "Subscription updates are not available.");
                flagEndAsync();
                if (listener != null)
                    listener.onInAppBillingPurchaseFinished(r, null);
                return;
            }
            buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldSkus, sku,
                    itemType, extraData);
        }
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new InAppBillingResult(response, "Unable to buy item");
            if (listener != null)
                listener.onInAppBillingPurchaseFinished(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();
        flagEndAsync();

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

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

From source file:com.kreggysoft.Billing.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./*from www. j ava2 s .c  o  m*/
 * 
 * @param act
 *            The calling activity.
 * @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);
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        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);

        }
        if (pendingIntent == null) {
            flagEndAsync();
            return;
        }

        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        // if (pendingIntent!=null)
        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.intel.moe.frameworks.inapppurchase.android.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 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./*w ww.  j a  v  a2  s.  com*/
 * @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 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(Object act, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(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));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(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;
        Class activityClass = Class.forName("android.app.Activity");

        Class[] paramTypes = new Class[] { IntentSender.class, int.class, Intent.class, int.class, int.class,
                int.class };
        Method method = activityClass.getMethod("startIntentSenderForResult", paramTypes);

        Object[] args = new Object[] { pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0) };

        method.invoke(act, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IntentSender.SendIntentException) {
            logError("SendIntentException while launching purchase flow for sku " + sku);
            e.printStackTrace();
            flagEndAsync();

            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();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}