List of usage examples for android.app PendingIntent getIntentSender
public IntentSender getIntentSender()
From source file:com.flat20.fingerplay.FingerPlayActivity.java
private void subscribe() { try {/*from w w w.j a va2 s .c o m*/ Bundle bundle = mBillingService.getBuyIntent(3, getPackageName(), IAP_SUBS_KEY, "subs", null); PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT"); if (bundle.getInt("RESPONSE_CODE") == 0) { startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_PURCHASE, new Intent(), 0, 0, 0); } else { unableToVerifyLicense(getString(R.string.billing_error_during_process), true); } } catch (Exception e) { Log.e("Fingerplay", "Error subscribing", e); unableToVerifyLicense(getString(R.string.billing_error_during_process), true); } }
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 ww. jav a 2s .c o m 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:org.linphone.purchase.InAppPurchaseHelper.java
private void purchaseItem(String productId, String sipIdentity) { Bundle buyIntentBundle = null;/*w ww . j a v a 2 s.co m*/ try { buyIntentBundle = mService.getBuyIntent(API_VERSION, mContext.getPackageName(), productId, ITEM_TYPE_SUBS, sipIdentity); } catch (RemoteException e) { Log.e(e); } if (buyIntentBundle != null) { PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT); if (pendingIntent != null) { try { ((Activity) mContext).startIntentSenderForResult(pendingIntent.getIntentSender(), ACTIVITY_RESULT_CODE_PURCHASE_ITEM, new Intent(), 0, 0, 0); } catch (SendIntentException e) { Log.e(e); } } } }
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 a va 2 s .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.otaupdater.SettingsActivity.java
private void showGetProKeyDialog() { if (cfg.hasProKey()) return;//from w w w . j a v a 2s . co m AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.settings_prokey_title); final boolean playServices = Utils.checkPlayServices(this); builder.setItems(playServices ? R.array.prokey_ops : R.array.prokey_ops_nomarket, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which -= playServices ? 1 : 0; switch (which) { case -1: try { Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(), Config.PROKEY_SKU, "inapp", null); PendingIntent buyIntent = buyIntentBundle.getParcelable("BUY_INTENT"); if (buyIntent != null) startIntentSenderForResult(buyIntent.getIntentSender(), PROKEY_REQ_CODE, new Intent(), 0, 0, 0); } catch (Exception e) { Toast.makeText(SettingsActivity.this, R.string.prokey_error_init, Toast.LENGTH_SHORT).show(); } break; case 0: redeemProKey(); break; // case 1: // startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SITE_BASE_URL + Config.DONATE_URL))); // break; } } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); }
From source file:org.anhonesteffort.flock.SubscriptionGoogleFragment.java
private void handleStartPurchaseIntent(PendingIntent purchaseIntent) { try {// ww w. j a v a2 s . c o m subscriptionActivity.startIntentSenderForResult(purchaseIntent.getIntentSender(), REQUEST_CODE_GOOGLE_FRAGMENT, new Intent(), 0, 0, 0); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "lol wut?", e); Toast.makeText(subscriptionActivity, R.string.google_play_error_please_update_google_play_services, Toast.LENGTH_LONG).show(); } }
From source file:com.thunder.iap.IAPActivity.java
/** * this methods is needed when a user wants to buy a subscription * @param sku// w ww . ja v a2s .co m * @param developerPayload * @param buySubscriptionListener */ public void buySubscription(final String sku, final String developerPayload, final BuySubscriptionListener buySubscriptionListener) { this.buySubscriptionListener = buySubscriptionListener; new Thread(new Runnable() { @Override public void run() { try { Bundle bundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", developerPayload); PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT"); if (bundle.getInt("RESPONSE_CODE") == 0) { // Start purchase flow (this brings up the Google Play UI). // Result will be delivered through onActivityResult(). try { startIntentSenderForResult(pendingIntent.getIntentSender(), RC_SUBS_BUY, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); buySubscriptionListener.onError(e); } } else { buySubscriptionListener.onServerError(bundle); } } catch (RemoteException e) { e.printStackTrace(); buySubscriptionListener.onError(e); } } }).start(); }
From source file:ir.aarani.bazaar.billing.BillingProcessor.java
private boolean purchase(Activity activity, List<String> oldProductIds, String productId, String purchaseType, String developerPayload) { if (!isInitialized() || TextUtils.isEmpty(productId) || TextUtils.isEmpty(purchaseType)) return false; try {//from www. j a va 2 s .co m String purchasePayload = purchaseType + ":" + productId; if (!purchaseType.equals(Constants.PRODUCT_TYPE_SUBSCRIPTION)) { purchasePayload += ":" + UUID.randomUUID().toString(); } if (developerPayload != null) { purchasePayload += ":" + developerPayload; } savePurchasePayload(purchasePayload); Bundle bundle; if (oldProductIds != null && purchaseType.equals(Constants.PRODUCT_TYPE_SUBSCRIPTION)) bundle = billingService.getBuyIntentToReplaceSkus(Constants.GOOGLE_API_SUBSCRIPTION_CHANGE_VERSION, contextPackageName, oldProductIds, productId, purchaseType, purchasePayload); else 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 && pendingIntent != 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(); TransactionDetails details = getPurchaseTransactionDetails(productId); if (!checkMerchant(details)) { Log.i(LOG_TAG, "Invalid or tampered merchant id!"); if (eventHandler != null) eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_MERCHANT_ID, null); return false; } if (eventHandler != null) { 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, "Error in purchase", e); if (eventHandler != null) eventHandler.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, e); } return false; }
From source file:com.mobileobservinglog.support.billing.DonationBillingHandler.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 .java 2 s . c o 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, OnPurchaseFinishedListener listener, String extraData) { Log.d("InAppPurchase", "Purchase Flow started -- handler"); BillingHandlerResult result; purchaseListener = listener; try { checkSetupDone("launchPurchaseFlow"); } catch (IllegalStateException e) { Log.d("InAppPurchase", "Setup was not done -- handler"); result = new BillingHandlerResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE, "Setup was not finished yet"); if (listener != null) listener.onPurchaseFinished(result, null); return; } flagStartAsync("launchPurchaseFlow"); try { Log.d("InAppPurchase", "Starting the purchase try -- handler"); Bundle buyIntentBundle = service.getBuyIntent(3, context.getPackageName(), sku, ITEM_TYPE_INAPP, extraData); int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { Log.d("InAppPurchase", "The response code from the bundle was not OK -- handler"); //In case we have a managed item that needs to be consumed. Bit of a hack. But works for now if (response == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) { String packageName = context.getPackageName(); service.consumePurchase(3, packageName, "inapp:" + packageName + ":" + sku); buyIntentBundle = service.getBuyIntent(3, packageName, sku, ITEM_TYPE_INAPP, extraData); } } PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT); this.requestCode = requestCode; Log.d("InAppPurchase", "About to start the intent sender for result -- handler"); if (pendingIntent != null) { act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)); Log.d("InAppPurchase", "Done with the intent sender for result -- handler"); } else { result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED, "Failed to send intent. We had a null pending intent"); if (purchaseListener != null) purchaseListener.onPurchaseFinished(result, null); } } catch (SendIntentException e) { Log.d("InAppPurchase", "Caught a SendIntentException -- handler"); e.printStackTrace(); result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED, "Failed to send intent."); if (purchaseListener != null) purchaseListener.onPurchaseFinished(result, null); } catch (RemoteException e) { Log.d("InAppPurchase", "Caught RemoteException -- handler"); e.printStackTrace(); result = new BillingHandlerResult(BILLINGHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow"); if (purchaseListener != null) purchaseListener.onPurchaseFinished(result, null); } }
From source file:com.turbulenz.turbulenz.googlepayment.java
void uiThreadDoPurchase(String sku, String extraData) { _log("uiThreadDoPurchase: sku: " + sku); try {//from w w w .jav a 2 s .c o m Bundle buyIntentBundle = mService.getBuyIntent(3, mActivity.getPackageName(), sku, ITEM_TYPE_INAPP, extraData); int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { _log("uiThreadDoPurchase: Failed to create intent bundle, " + "response: " + response); sendPurchaseFailure(mPurchaseContext, "failed to create Android buy Intent"); return; } PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT); _log("uiThreadDoPurchase: launching buy intent for sku: " + sku + ", with request code: " + mPurchaseRequestCode); mActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), mPurchaseRequestCode, new Intent(), Integer.valueOf(0), // flagsMask Integer.valueOf(0), // flagsValues Integer.valueOf(0)); // extraFlags } catch (SendIntentException e) { _error("uiThreadDoPurchase: SendIntentException"); e.printStackTrace(); sendPurchaseFailure(mPurchaseContext, "failed to send intent"); } catch (RemoteException e) { _error("uiThreadDoPurchase: RemoteException"); e.printStackTrace(); sendPurchaseFailure(mPurchaseContext, "RemoteException: " + e); } }