List of usage examples for android.os Bundle getParcelable
@Nullable public <T extends Parcelable> T getParcelable(@Nullable String key)
From source file:co.techmagic.inapppurchasesintegrationsample.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./*ww 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(BillingActivity act, String sku, String itemType, List<String> oldSkus, 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; 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:com.smartmobilesoftware.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 w w . ja va2 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) * ITEM_TYPE_SUBS) * @param oldPurchasedSkus 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> oldPurchasedSkus, int requestCode, OnIabPurchaseFinishedListener listener, String extraData) { checkNotDisposed(); checkSetupDone("launchPurchaseFlow"); flagStartAsync("launchPurchaseFlow"); IabResult result; if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) { IabResult r = new IabResult(ERR_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 (oldPurchasedSkus == null || oldPurchasedSkus.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(ERR_SUBSCRIPTION_UPDATE_NOT_AVAILABLE, "Subscription updates are not available."); flagEndAsync(); if (listener != null) listener.onIabPurchaseFinished(r, null); return; } buyIntentBundle = mService.getBuyIntentToReplaceSkus(5, mContext.getPackageName(), oldPurchasedSkus, 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(ERR_PURCHASE, "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(ERR_COMMUNICATION, "Remote exception while starting purchase flow"); if (listener != null) listener.onIabPurchaseFinished(result, null); } }
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./*w ww . jav 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; 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: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 ww w. j a va2 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)); 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.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 w w .j ava2s. 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); } 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.neusou.bioroid.restful.RestfulClient.java
/** * Executes HTTP method// ww w . j a va2 s .com * @param <T> Http Request Method class * @param <V> Restful response class * @param <M> restful method class * @param <R> response handler class * @param httpMethod http request method * @param rh response handler * @param data extra invocation data */ public <T extends HttpRequestBase, V extends IRestfulResponse<?>, M extends RestfulMethod, R extends RestfulResponseHandler<V, M>> void execute( final T httpMethod, R rh, final Bundle data) { Logger.l(Logger.DEBUG, LOG_TAG, "execute() " + httpMethod.getRequestLine().toString()); DefaultHttpClient httpClient = new DefaultHttpClient(); V response = null; String exceptionMessage = null; String cachedResponse = null; boolean isResponseCached = data.getBoolean(KEY_USE_CACHE, mUseCacheByDefault); String requestUrl = httpMethod.getRequestLine().getUri().toString(); Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # useCache? " + isResponseCached); if (mResponseCacheInitialized && isResponseCached) { httpMethod.getParams().setBooleanParameter("param1", true); //Log.d(LOG_TAG, "paramstring: "+paramString); cachedResponse = mCacheResponseDbHelper.getResponse(requestUrl, httpMethod.getMethod()); Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # cached response: " + cachedResponse); response = rh.createResponse(cachedResponse); response.set(new StringReader(cachedResponse)); } if (cachedResponse == null) { try { response = httpClient.execute(httpMethod, rh); } catch (ClientProtocolException e) { e.printStackTrace(); exceptionMessage = e.getMessage(); httpMethod.abort(); } catch (UnknownHostException e) { e.printStackTrace(); exceptionMessage = "not connected to the internet"; httpMethod.abort(); } catch (IOException e) { e.printStackTrace(); exceptionMessage = "connection error. please try again."; httpMethod.abort(); } // cache the response if (exceptionMessage == null && mResponseCacheInitialized && isResponseCached) { Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # inserting response to cache: " + response); M method = data.getParcelable(XTRA_METHOD); BufferedReader br = new BufferedReader(response.get()); StringBuilder sb = new StringBuilder(); char[] buffer = new char[51200]; try { while (true) { int bytesRead; bytesRead = br.read(buffer); if (bytesRead == -1) { break; } sb.append(buffer, 0, bytesRead); } mCacheResponseDbHelper.insertResponse(requestUrl, sb.toString(), Calendar.getInstance().getTime().getTime(), httpMethod.getMethod(), method.getCallId()); } catch (IOException e) { e.printStackTrace(); } } } // process response //Logger.l(Logger.DEBUG, LOG_TAG, "starting service with action: "+INTENT_PROCESS_RESPONSE); Intent processIntent = new Intent(); processIntent.setAction(INTENT_PROCESS_RESPONSE); processIntent.putExtra(XTRA_RESPONSE, response); processIntent.putExtra(XTRA_ERROR, exceptionMessage); processIntent.putExtra(XTRA_REQUEST, data); mContext.startService(processIntent); boolean imcallback = data.getBoolean(KEY_IMMEDIATECALLBACK, false); if (imcallback) { Bundle callbackData = new Bundle(); callbackData.putBundle(XTRA_REQUEST, data); callbackData.putParcelable(XTRA_RESPONSE, response); callbackData.putString(XTRA_ERROR, exceptionMessage); broadcastCallback(mContext, callbackData, generateKey(mContext.getPackageName(), mName, RestfulClient.KEY_CALLBACK_INTENT)); } }
From source file:com.kyleshaver.minuteofangle.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 w w w . j av a2 s . c o m*/ * @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 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) { 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 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 = 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.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.// w w w .j av a2s . 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.grupohqh.carservices.operator.ManipulateCarActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_manipulate_car); if (getIntent().getExtras().containsKey("userId")) userId = getIntent().getExtras().getInt("userId"); if (getIntent().getExtras().containsKey("carOwnerId")) carOwnerId = getIntent().getExtras().getInt("carOwnerId"); CARBRAND_URL = getString(R.string.base_url) + getString(R.string.carbrands_url); CARLINE_URL = getString(R.string.base_url) + getString(R.string.carmodels_url); SAVECAR_URL = getString(R.string.base_url) + "savecar/"; SAVEPHOTO_URL = getString(R.string.base_url) + "savephoto/"; hasCamera = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); etTagNumber = (EditText) findViewById(R.id.etTagNumber); etUsernameOwner = (EditText) findViewById(R.id.etUsernameOwner); etCarBrand = (EditText) findViewById(R.id.etCarBrand); etCarModel = (EditText) findViewById(R.id.etCarModel); etCarYear = (EditText) findViewById(R.id.etCarYear); etColor = (EditText) findViewById(R.id.etCarColor); etSerialNumber = (EditText) findViewById(R.id.etSerialNumber); etLicensePlate = (EditText) findViewById(R.id.etLicensePlate); etKM = (EditText) findViewById(R.id.etKm); imgCar = (ImageView) findViewById(R.id.imgCar); spCarBrand = (Spinner) findViewById(R.id.spCarBrand); spCarModel = (Spinner) findViewById(R.id.spCarModel); btnSaveCar = (Button) findViewById(R.id.btnSaveCar); btnTakePicture = (Button) findViewById(R.id.btnTakePicture); bar = (ProgressBar) findViewById(R.id.progressBar); viewUsername = findViewById(R.id.viewUsername); if (savedInstanceState != null) { bm = savedInstanceState.getParcelable("bm"); if (bm != null) imgCar.setImageBitmap(bm);/*www . j av a2 s . c o m*/ } bar.setVisibility(View.GONE); etCarBrand.setVisibility(View.GONE); etCarModel.setVisibility(View.GONE); viewUsername.setVisibility(carOwnerId == 0 ? View.VISIBLE : View.GONE); btnTakePicture.setEnabled(hasCamera); btnTakePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(ManipulateCarActivity.this))); startActivityForResult(intent, CAPTURE_IMAGE); } }); btnSaveCar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validate()) new SaveCarAsyncTask().execute(SAVECAR_URL); } }); spCarBrand.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY); if (mapBrands.get(brands.get(position)) == otherId) { etCarBrand.setVisibility(View.VISIBLE); etCarModel.setVisibility(View.VISIBLE); spCarModel.setVisibility(View.GONE); etCarBrand.requestFocus(); } else { etCarBrand.setVisibility(View.GONE); etCarModel.setVisibility(View.GONE); spCarModel.setVisibility(View.VISIBLE); new LoadCarModelsAsyncTask().execute(CARLINE_URL + mapBrands.get(brands.get(position)) + "/"); reload = true; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spCarModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY); if (mapModels.get(models.get(position)) == otherId) { etCarModel.setVisibility(View.VISIBLE); etCarModel.requestFocus(); } else { etCarModel.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); if (useMiniMe) { manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbCommunication = UsbCommunication.newInstance(); IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); // will intercept by system filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); filter.addAction(ACTION_USB_PERMISSION); registerReceiver(usbReceiver, filter); etEPC = (EditText) findViewById(R.id.etEPC); btnReadTAG = (Button) findViewById(R.id.btnReadTAG); txtStatus = (TextView) findViewById(R.id.txtStatus); btnReadTAG.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { etEPC.setText(""); if (txtStatus.getText().toString().equals("conectado")) { readTag(); } else { Toast.makeText(getBaseContext(), "dispositivo " + txtStatus.getText(), Toast.LENGTH_LONG) .show(); } } }); } etKM.addTextChangedListener(new NumberTextWatcher(etKM)); }