Example usage for android.app Activity startIntentSenderForResult

List of usage examples for android.app Activity startIntentSenderForResult

Introduction

In this page you can find the example usage for android.app Activity startIntentSenderForResult.

Prototype

public void startIntentSenderForResult(IntentSender intent, int requestCode, @Nullable Intent fillInIntent,
        int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException 

Source Link

Document

Same as calling #startIntentSenderForResult(IntentSender,int,Intent,int,int,int,Bundle) with no options.

Usage

From source file:com.felkertech.n.ActivityUtils.java

public static void syncFile(Activity activity, GoogleApiClient gapi) {
    if (DEBUG) {/*from ww w .  j  ava2s . c o m*/
        Log.d(TAG, "About to sync a file");
    }
    if (gapi == null && GoogleDrive.gapi != null) {
        gapi = GoogleDrive.gapi;
    } else if (GoogleDrive.gapi == null) {
        // Is not existant
        return;
    }
    if (gapi.isConnected()) {
        IntentSender intentSender = Drive.DriveApi.newOpenFileActivityBuilder()
                .setMimeType(new String[] { "application/json", "text/*" }).build(gapi);
        try {
            if (DEBUG) {
                Log.d(TAG, "About to start activity");
            }
            activity.startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
            if (DEBUG) {
                Log.d(TAG, "Activity activated");
            }
        } catch (IntentSender.SendIntentException e) {
            if (DEBUG) {
                Log.w(TAG, "Unable to send intent", e);
            }
            e.printStackTrace();
        }
    } else {
        Toast.makeText(activity, R.string.toast_msg_wait_google_api_client, Toast.LENGTH_SHORT).show();
    }
}

From source file:jp.alessandro.android.iab.PurchaseFlowLauncher.java

private void startBuyIntent(final Activity activity, final PendingIntent pendingIntent, int requestCode)
        throws BillingException {

    IntentSender sender = pendingIntent.getIntentSender();
    try {/*from w  w  w.  j  a  va 2s. c o m*/
        activity.startIntentSenderForResult(sender, requestCode, new Intent(), 0, 0, 0);

    } catch (IntentSender.SendIntentException e) {
        throw new BillingException(Constants.ERROR_SEND_INTENT_FAILED, e.getMessage());
    }
}

From source file:net.kourlas.voipms_sms.Billing.java

private void showDonationDialog(Activity sourceActivity) {
    try {// ww  w  .ja v a2s .c om
        Bundle buyIntentBundle = billingService.getBuyIntent(3, applicationContext.getPackageName(),
                applicationContext.getString(R.string.billing_pid_donation), "inapp", null);
        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
        sourceActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
    } catch (Exception ex) {
        Utils.showInfoDialog(sourceActivity, applicationContext.getString(R.string.billing_failure));
    }
}

From source file:com.tangrainc.inappbilling.InAppBillingHelper.java

public void startBuyIntent(Activity foregroundActivity, String productIdentifier, String payload)
        throws Exception {
    Bundle buyIntentBundle = _service.getBuyIntent(3, _context.getPackageName(), productIdentifier, "inapp",
            payload);/* w  w  w .  ja  v  a 2s .co  m*/
    PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

    if (pendingIntent == null) {
        throw new Exception("Product already purchased!");
    }

    foregroundActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), BUY_INTENT_REQUEST_CODE,
            new Intent(), 0, 0, 0);
}

From source file:com.nokia.example.pepperfarm.iap.Payment.java

/**
 * Starts the payment process for the given product id. Application is suspended and the Npay service will complete the purchase.
 *
 * @param caller     - The response from the purchase is sent to the caller activity. Caller activity must override "protected void onActivityResult(int requestCode, int resultCode, Intent data)" method to get the response.
 * @param product_id - The product id that is being purchased.
 * @throws Exception//from   w w  w.  j av  a  2s .c  o  m
 */
public void startPayment(Activity caller, String product_id) throws Exception {

    if (!isBillingAvailable())
        return;

    Bundle intentBundle = npay.getBuyIntent(API_VERSION, activity.getPackageName(), product_id, ITEM_TYPE_INAPP,
            "");
    PendingIntent purchaseIntent = intentBundle.getParcelable("BUY_INTENT");

    //Set purchase in progress
    setPurchaseInProgress(product_id);

    caller.startIntentSenderForResult(purchaseIntent.getIntentSender(), Integer.valueOf(0), new Intent(),
            Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));

}

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;// w w w.  j a  va 2  s . co m
    }

    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.anjlab.android.iab.v3.BillingProcessor.java

private boolean purchase(Activity activity, String productId, String purchaseType) {
    if (!isInitialized() || TextUtils.isEmpty(productId) || TextUtils.isEmpty(purchaseType))
        return false;
    try {/*w w  w . j ava  2s.  c  om*/
        String purchasePayload = purchaseType + ":" + UUID.randomUUID().toString();
        savePurchasePayload(purchasePayload);
        Bundle bundle = billingService.getBuyIntent(Constants.GOOGLE_API_VERSION, contextPackageName, productId,
                purchaseType, purchasePayload);
        if (bundle != null) {
            int response = bundle.getInt(Constants.RESPONSE_CODE);
            if (response == Constants.BILLING_RESPONSE_RESULT_OK) {
                PendingIntent pendingIntent = bundle.getParcelable(Constants.BUY_INTENT);
                if (activity != null)
                    activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                            PURCHASE_FLOW_REQUEST_CODE, new Intent(), 0, 0, 0);
                else if (eventHandler != null)
                    eventHandler.onBillingError(Constants.BILLING_ERROR_LOST_CONTEXT, null);
            } else if (response == Constants.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                if (!isPurchased(productId) && !isSubscribed(productId))
                    loadOwnedPurchasesFromGoogle();
                if (eventHandler != null) {
                    TransactionDetails details = getPurchaseTransactionDetails(productId);
                    if (details == null)
                        details = getSubscriptionTransactionDetails(productId);
                    eventHandler.onProductPurchased(productId, details);
                }
            } else if (eventHandler != null)
                eventHandler.onBillingError(Constants.BILLING_ERROR_FAILED_TO_INITIALIZE_PURCHASE, null);
        }
        return true;
    } catch (Exception e) {
        Log.e(LOG_TAG, e.toString());
    }
    return false;
}

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;/*  w  w  w.ja v  a  2s .  co 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:com.appsimobile.appsii.iab.IabPurchaseHelper.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/*w  w w  .j  a v a 2 s. com*/
 * 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 developerPayload 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 int launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
        String developerPayload) {
    checkSetupDone("launchPurchaseFlow");

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        return IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE;
    }

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

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

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;//from www  .j  a  v  a 2s. co 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);
    }
}