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.eurecalab.eureca.fragments.SettingsFragment.java

private void upgradePro() {
    try {// w  w  w.ja v  a2s. c  o  m
        Bundle buyIntentBundle = mService.getBuyIntent(GenericConstants.BILLING_VERSION,
                getActivity().getPackageName(), GenericConstants.PREMIUM_VERSION_SKU, "inapp",
                "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
        if (pendingIntent != null) {
            getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(),
                    GenericConstants.PURCHASE_REQUEST_CODE, new Intent(), 0, 0, 0);
        } else {
            Snackbar.make(upgrade, R.string.item_already_purchased, Snackbar.LENGTH_LONG).show();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}

From source file:com.firebase.ui.auth.util.signincontainer.SaveSmartLock.java

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Toast.makeText(getContext(), R.string.general_error, Toast.LENGTH_SHORT).show();

    PendingIntent resolution = PlayServicesHelper.getGoogleApiAvailability()
            .getErrorResolutionPendingIntent(getContext(), connectionResult.getErrorCode(), RC_UPDATE_SERVICE);
    try {/*from  w  w  w.jav  a2s . c o m*/
        mHelper.startIntentSenderForResult(resolution.getIntentSender(), RC_UPDATE_SERVICE);
    } catch (IntentSender.SendIntentException e) {
        Log.e(TAG, "STATUS: Failed to send resolution.", e);
        finish();
    }
}

From source file:com.jetheis.android.makeitrain.billing.googleplay.GooglePlayBillingWrapper.java

public void requestVipStatus() {
    Bundle response;/*from w ww  . ja  v  a2s. com*/

    try {
        response = mBoundService.makeGooglePlayPurchaseRequest(Constants.GOOGLE_PLAY_PRODUCT_ID);
    } catch (RemoteException e) {
        Log.e(Constants.TAG, "RemoteException: " + e.getLocalizedMessage());
        return;
    }

    if (response.getInt(Constants.GOOGLE_PLAY_BUNDLE_KEY_RESPONSE_CODE) != GooglePlayResponseCode.RESULT_OK
            .ordinal()) {
        return;
    }

    PendingIntent pendingIntent = response.getParcelable(Constants.GOOGLE_PLAY_BUNDLE_KEY_PURCHASE_INTENT);

    try {
        mContext.startIntentSender(pendingIntent.getIntentSender(), new Intent(), 0, 0, 0);
    } catch (SendIntentException e) {
        Log.e(Constants.TAG, "SendIntentException: " + e.getLocalizedMessage());
    }
}

From source file:net.olejon.spotcommander.DonateActivity.java

private void makeDonation(final String product) {
    try {/*from  w w w  .  j a  v a2 s  .co  m*/
        final Bundle buyIntentBundle = mIInAppBillingService.getBuyIntent(3, getPackageName(), product, "inapp",
                "");

        final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

        final IntentSender intentSender = (pendingIntent != null) ? pendingIntent.getIntentSender() : null;

        startIntentSenderForResult(intentSender, 1, new Intent(), 0, 0, 0);
    } catch (Exception e) {
        mTools.showToast(getString(R.string.donate_something_went_wrong), 1);

        Log.e("DonateActivity", Log.getStackTraceString(e));
    }
}

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/*from   w  w w.j  a v a 2s.  co m*/
 * 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:de.j4velin.wifiAutoOff.Locations.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Database db = Database.getInstance(this);
    locations = db.getLocations();// w  ww .  j  a v a 2s .c  om
    db.close();

    setContentView(R.layout.locations);

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (PREMIUM_ENABLED || locations.size() < 1) {
                startActivityForResult(new Intent(Locations.this, Map.class), REQUEST_LOCATION);
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(Locations.this);
                builder.setMessage(R.string.buy_pro);
                builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, int which) {
                        try {
                            Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                                    "de.j4velin.wifiautomatic.billing.pro", "inapp", getPackageName());
                            if (buyIntentBundle.getInt("RESPONSE_CODE") == 0) {
                                PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                                startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_BUY, null,
                                        0, 0, 0);
                            }
                        } catch (Exception e) {
                            if (BuildConfig.DEBUG)
                                Logger.log(e);
                            Toast.makeText(Locations.this, e.getClass().getName() + ": " + e.getMessage(),
                                    Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                        }
                        dialog.dismiss();
                    }
                });
                builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.create().show();
            }
        }
    });

    mRecyclerView = (RecyclerView) findViewById(R.id.locations);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mAdapter = new LocationsAdapter();
    mRecyclerView.setAdapter(mAdapter);

    PREMIUM_ENABLED |= getSharedPreferences("settings", Context.MODE_PRIVATE).getBoolean("pro", false);
    if (!PREMIUM_ENABLED) {
        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);
    }

    findViewById(R.id.timeoutwarning).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            getSharedPreferences(getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS).edit()
                    .putInt("no_network_timeout", 5).commit();
            v.setVisibility(View.GONE);
        }
    });

}

From source file:me.henrytao.bootstrapandroidlibrarydemo.activity.BaseActivity.java

private void onDonate(PurchaseItem item) {
    if (item == null || !item.isValid() || mBillingService == null) {
        return;//from   w ww . ja v  a2  s.  c o  m
    }
    try {
        Bundle buyIntentBundle = mBillingService.getBuyIntent(3, getPackageName(), item.getId(), "inapp", "");
        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
        startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}

From source file:com.jetheis.android.grades.billing.googleplay.GooglePlayBillingWrapper.java

@Override
public void requestPurchase(String itemId) {
    Log.d(Constants.TAG, "Requesting purchase of " + itemId);

    Bundle response;/*from  w w w .  ja  va  2s .  c  o  m*/

    try {
        response = mBoundService.makeGooglePlayPurchaseRequest(itemId);
    } catch (RemoteException e) {
        Log.e(Constants.TAG, "RemoteException: " + e.getLocalizedMessage());
        return;
    }

    if (response.getInt(
            GooglePlayBillingConstants.GOOGLE_PLAY_BUNDLE_KEY_RESPONSE_CODE) != GooglePlayResponseCode.RESULT_OK
                    .ordinal()) {
        return;
    }

    PendingIntent pendingIntent = response
            .getParcelable(GooglePlayBillingConstants.GOOGLE_PLAY_BUNDLE_KEY_PURCHASE_INTENT);

    try {
        mContext.startIntentSender(pendingIntent.getIntentSender(), new Intent(), 0, 0, 0);
    } catch (SendIntentException e) {
        Log.e(Constants.TAG, "SendIntentException: " + e.getLocalizedMessage());
    }

}

From source file:com.thunder.iap.IAPActivity.java

/**
 *
 * @param sku the item that the user wants to buy
 * @param developerPayload the developer payload string, more info here http://developer.android.com/training/in-app-billing/purchase-iab-products.html
 * @param buyItemListener/*  w  ww .ja va  2 s  . c  om*/
 */
public void buyItem(final String sku, final String developerPayload, final BuyItemListener buyItemListener) {
    this.buyItemListener = buyItemListener;
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "inapp",
                        developerPayload);
                int response = buyIntentBundle.getInt("RESPONSE_CODE");
                if (response == 0) {
                    PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                    try {
                        startIntentSenderForResult(pendingIntent.getIntentSender(), RC_INAPP_BUY, new Intent(),
                                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        //the onSuccess callback of the listener will be called on the method onActivityResult
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                        buyItemListener.onError(e);
                    }
                } else {
                    buyItemListener.onServerError(buyIntentBundle);
                }
            } catch (RemoteException e) {
                e.printStackTrace();
                buyItemListener.onError(e);
            }
        }
    }).start();
}

From source file:com.nokia.example.paymentoneapk.PaymentOneAPKActivity.java

public void launchPurchase(final String sku, final String itemType, final int requestCode,
        final String extraData) {

    Log.d(TAG, "PaymentOneAPKActivity.launchPurchase");

    try {/*from w  w  w  . j  a v  a2s  . c om*/
        final Bundle buyIntentBundle = mService.getBuyIntent(API_VERSION, getPackageName(), sku, itemType,
                extraData);

        final int response = buyIntentBundle.getInt("RESPONSE_CODE");

        if (response != PaymentOneAPKUtils.RESULT_OK) {

            Log.e(TAG, String.format("error while buying. response=%s", getErrorMessage(response)));
            toastMessage(String.format("Got an error while buying: %s", getErrorMessage(response)));

            return;
        }

        final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

        Log.d(TAG, String.format("pendingIntent = %s", pendingIntent));

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

    } catch (final RemoteException e) {
        Log.e(TAG, "error while buying", e);
        toastMessage("Got an exception while buying");
    } catch (final IntentSender.SendIntentException e) {
        Log.e(TAG, "error while buying", e);
        toastMessage("Got an exception while buying");
    }
}