List of usage examples for android.content Intent getExtras
public @Nullable Bundle getExtras()
From source file:com.facebook.AccessToken.java
/** * Creates a new AccessToken using the information contained in an Intent populated by the * Facebook application in order to launch a native link. For more information on native * linking, please see https://developers.facebook.com/docs/mobile/android/deep_linking/. * * @param intent the Intent that was used to start an Activity; must not be null * @param applicationId the ID of the Facebook Application associated with this access token */// w w w .j av a2s .c om public static void createFromNativeLinkingIntent(Intent intent, final String applicationId, final AccessTokenCreationCallback accessTokenCallback) { Validate.notNull(intent, "intent"); if (intent.getExtras() == null) { accessTokenCallback.onError(new FacebookException("No extras found on intent")); return; } final Bundle extras = new Bundle(intent.getExtras()); String accessToken = extras.getString(ACCESS_TOKEN_KEY); if (accessToken == null || accessToken.isEmpty()) { accessTokenCallback.onError(new FacebookException("No access token found on intent")); return; } String userId = extras.getString(USER_ID_KEY); // Old versions of facebook for android don't provide the UserId. Obtain the id if missing if (userId == null || userId.isEmpty()) { Utility.getGraphMeRequestWithCacheAsync(accessToken, new Utility.GraphMeRequestWithCacheCallback() { @Override public void onSuccess(JSONObject userInfo) { try { String userId = userInfo.getString("id"); extras.putString(USER_ID_KEY, userId); accessTokenCallback.onSuccess(createFromBundle(null, extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), applicationId)); } catch (JSONException ex) { accessTokenCallback.onError( new FacebookException("Unable to generate access token due to missing user id")); } } @Override public void onFailure(FacebookException error) { accessTokenCallback.onError(error); } }); } else { accessTokenCallback.onSuccess(createFromBundle(null, extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), applicationId)); } }
From source file:com.android.launcher3.InstallShortcutReceiver.java
/** * Returns true if the intent is a valid launch intent for a shortcut. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file.// ww w .j a va 2 s . co m * * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be * duplicated or removed(unless the app is un-installed). * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ static boolean isValidShortcutLaunchIntent(Intent launchIntent) { if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction()) && launchIntent.getComponent() != null && launchIntent.getCategories() != null && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && launchIntent.getExtras() == null && TextUtils.isEmpty(launchIntent.getDataString())) { return false; } return true; }
From source file:Main.java
/** * Returns a bitmap from a gallery Uri/*from w ww . j a v a 2 s. com*/ * * @param pContext * Context required to access the content resolver * @param pIntent * The Uri of the picker image * @return The picked image as a bitmap */ public static Bitmap getBitmapFromIntent(Context pContext, Intent pIntent) { Bitmap bitmapPickedImage = null; Uri pickedImageUri = pIntent.getData(); // If the URI is not null try to decode it to a bitmap else try to get the bitmap data from the intent // http://stackoverflow.com/questions/17123083/null-pointer-exception-while-taking-pictures-from-camera-android-htc if (pickedImageUri != null) { try { InputStream imageStream = pContext.getContentResolver().openInputStream(pickedImageUri); bitmapPickedImage = BitmapFactory.decodeStream(imageStream); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { if (pIntent.getExtras() != null && pIntent.getExtras().get("data") instanceof Bitmap) { bitmapPickedImage = (Bitmap) pIntent.getExtras().get("data"); } } return bitmapPickedImage; }
From source file:bolts.MeasurementEvent.java
/** * Broadcast Bolts measurement event.//from w ww . j a v a 2 s. c o m * Bolts raises events to the application with this method by sending * {@link #MEASUREMENT_EVENT_NOTIFICATION_NAME} broadcast. * * @param context the context of activity or application who is going to send the event. required. * @param name the event name that is going to be sent. required. * @param intent the intent that carries the logging data in its extra bundle and data url. optional. * @param extraLoggingData other logging data to be sent in events argument. optional. * */ static void sendBroadcastEvent(Context context, String name, Intent intent, Map<String, String> extraLoggingData) { Bundle logData = new Bundle(); if (intent != null) { Bundle applinkData = AppLinks.getAppLinkData(intent); if (applinkData != null) { logData = getApplinkLogData(context, name, applinkData, intent); } else { Uri intentUri = intent.getData(); if (intentUri != null) { logData.putString("intentData", intentUri.toString()); } Bundle intentExtras = intent.getExtras(); if (intentExtras != null) { for (String key : intentExtras.keySet()) { Object o = intentExtras.get(key); String logValue = objectToJSONString(o); logData.putString(key, logValue); } } } } if (extraLoggingData != null) { for (String key : extraLoggingData.keySet()) { logData.putString(key, extraLoggingData.get(key)); } } MeasurementEvent event = new MeasurementEvent(context, name, logData); event.sendBroadcast(); }
From source file:at.wada811.utils.IntentUtils.java
public static String dump(Intent intent) throws JSONException { JSONObject json = new JSONObject(); json.put("action", intent.getAction()); if (intent.getCategories() != null) { JSONArray categories = new JSONArray(); for (String category : intent.getCategories()) { categories.put(category);/*from w w w.j a v a2 s. c o m*/ } json.put("category", categories); } json.put("type", intent.getType()); Bundle bundle = intent.getExtras(); if (bundle != null) { JSONObject extras = new JSONObject(); for (String key : bundle.keySet()) { extras.put(key, bundle.get(key)); } json.put("extras", extras); } return json.toString(4); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static void DownloadFromUrl(final String media, final String messageId, final Context ctx, final ImageView container, final Object object, final String timelineId, final String localId, final Long fileSize) { new AsyncTask<Void, Void, Boolean>() { private boolean retry = true; private Bitmap imageDownloaded; private BroadcastReceiver mDownloadCancelReceiver; private HttpGet job; private AccountManager am; private Account account; private String authToken; @Override/*from w w w .j ava2 s .com*/ protected void onPreExecute() { IntentFilter downloadFilter = new IntentFilter(ConstantKeys.BROADCAST_CANCEL_PROCESS); mDownloadCancelReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String localIdToClose = (String) intent.getExtras().get(ConstantKeys.LOCALID); if (localId.equals(localIdToClose)) { try { job.abort(); } catch (Exception e) { log.debug("The process was canceled"); } cancel(false); } } }; // registering our receiver ctx.getApplicationContext().registerReceiver(mDownloadCancelReceiver, downloadFilter); } @Override protected void onCancelled() { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); if (file1.exists()) { file1.delete(); } if (file2.exists()) { file2.delete(); } file1 = null; file2 = null; System.gc(); try { ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver); } catch (Exception e) { log.debug("Receriver unregister from another code"); } for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) { if (AppUtils.getlistOfDownload().get(i).equals(localId)) { AppUtils.getlistOfDownload().remove(i); } } DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100); Intent intent = new Intent(); intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH); intent.putExtra(ConstantKeys.LOCALID, localId); ctx.sendBroadcast(intent); if (object != null) { ((ProgressDialog) object).dismiss(); } } @Override protected Boolean doInBackground(Void... params) { try { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); // firt we are goint to search the local files if ((!file1.exists()) && (!file2.exists())) { account = AccountUtils.getAccount(ctx.getApplicationContext(), false); am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE); authToken = ConstantKeys.STRING_DEFAULT; authToken = am.blockingGetAuthToken(account, ctx.getString(R.string.account_type), true); MessagingClientService messageService = new MessagingClientService( ctx.getApplicationContext()); URL urlObj = new URL(Preferences.getServerProtocol(ctx), Preferences.getServerAddress(ctx), Preferences.getServerPort(ctx), ctx.getString(R.string.url_get_content)); String url = ConstantKeys.STRING_DEFAULT; url = Uri.parse(urlObj.toString()).buildUpon().build().toString() + timelineId + "/" + messageId + "/" + "content"; job = new HttpGet(url); // first, get free space FreeUpSpace(ctx, fileSize); messageService.getContent(authToken, media, messageId, timelineId, localId, false, false, fileSize, job); } if (file1.exists()) { imageDownloaded = decodeSampledBitmapFromPath(file1.getAbsolutePath(), 200, 200); } else if (file2.exists()) { imageDownloaded = ThumbnailUtils.createVideoThumbnail(file2.getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); } if (imageDownloaded == null) { return false; } return true; } catch (Exception e) { deleteFiles(); return false; } } @Override protected void onPostExecute(Boolean result) { // We have the media try { ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver); } catch (Exception e) { log.debug("Receiver was closed on cancel"); } if (!(localId.contains(ConstantKeys.AVATAR))) { for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) { if (AppUtils.getlistOfDownload().get(i).equals(localId)) { AppUtils.getlistOfDownload().remove(i); } } DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100); Intent intent = new Intent(); intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH); intent.putExtra(ConstantKeys.LOCALID, localId); ctx.sendBroadcast(intent); } if (object != null) { ((ProgressDialog) object).dismiss(); } // Now the only container could be the avatar in edit screen if (container != null) { if (imageDownloaded != null) { container.setImageBitmap(imageDownloaded); } else { deleteFiles(); imageDownloaded = decodeSampledBitmapFromResource(ctx.getResources(), R.drawable.ic_error_loading, 200, 200); container.setImageBitmap(imageDownloaded); Toast.makeText(ctx.getApplicationContext(), ctx.getApplicationContext().getText(R.string.donwload_fail), Toast.LENGTH_SHORT) .show(); } } else { showMedia(localId, ctx, (ProgressDialog) object); } } private void deleteFiles() { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); if (file1.exists()) { file1.delete(); } if (file2.exists()) { file2.delete(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.appsimobile.appsii.iab.IabPurchaseHelper.java
/** * Handles an activity result that's part of the purchase flow in in-app billing. If you * are calling {@link #launchPurchaseFlow}, then you must call this method from your * Activity's {@link android.app.Activity@onActivityResult} method. This method * MUST be called from the UI thread of the Activity. * * @param resultCode The resultCode as you received it. * @param data The data (Intent) as you received it. * * @return Returns true if the result was related to a purchase flow and was handled; * false if the result was not related to a purchase, in which case you should * handle it normally.//from w w w . j ava 2 s.com */ public static int handleActivityResult(int resultCode, Intent data, OnIabPurchaseFinishedListener purchaseListener, String itemType, String devPayload) { if (data == null) { logError("Null data in IAB activity result."); return IABHELPER_BAD_RESPONSE; } int responseCode = getResponseCodeFromIntent(data); String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA); String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE); if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) { logDebug("Successful resultcode from purchase activity."); logDebug("Purchase data: " + purchaseData); logDebug("Data signature: " + dataSignature); logDebug("Extras: " + data.getExtras()); logDebug("Expected item type: " + itemType); if (purchaseData == null || dataSignature == null) { logError("BUG: either purchaseData or dataSignature is null."); logDebug("Extras: " + data.getExtras().toString()); return IABHELPER_UNKNOWN_ERROR; } Purchase purchase; try { purchase = new Purchase(itemType, purchaseData, dataSignature); String sku = purchase.getSku(); // Verify signature if (!Security.verifyPurchase(RSA_CODE, purchaseData, dataSignature)) { logError("Purchase signature verification FAILED for sku " + sku); return IABHELPER_VERIFICATION_FAILED; } logDebug("Purchase signature successfully verified."); if (!Security.verifyDeveloperPayload(purchase, devPayload)) { logError("Purchase payload verification FAILED for sku " + sku); return IABHELPER_DEVELOPER_PAYLOAD_FAILED; } logDebug("Developer payload successfully verified."); } catch (JSONException e) { logError("Failed to parse purchase data."); e.printStackTrace(); return IABHELPER_BAD_RESPONSE; } if (purchaseListener != null) { purchaseListener.onIabPurchaseSuccess(purchase); } return BILLING_RESPONSE_RESULT_OK; } else if (resultCode == Activity.RESULT_OK) { // result code was OK, but in-app billing response was not OK. logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode)); return responseCode; } else if (resultCode == Activity.RESULT_CANCELED) { logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); return IABHELPER_USER_CANCELLED; } else { logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: " + getResponseDesc(responseCode)); return IABHELPER_UNKNOWN_PURCHASE_RESPONSE; } }
From source file:com.ademsha.appnotifico.NotificationHubDataReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent.getExtras() != null) { String command = intent.getStringExtra("command"); if (command.equals("get-all")) { String data = intent.getStringExtra("data"); JSONArray notifications;/*from w w w . j a v a 2 s .com*/ try { notifications = new JSONArray(data); for (int i = 0; i < notifications.length(); i++) { JSONObject notification = notifications.getJSONObject(i); Toast.makeText(context, notification.toString(), Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } } else { Toast.makeText(context, command, Toast.LENGTH_SHORT).show(); } } }
From source file:com.bandbaaja.c2dm.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { //TODO: do something with message }//from ww w. j ava2s. c o m }
From source file:com.commontime.plugin.notification.notification.AbstractClearReceiver.java
/** * Called when the notification was cleared from the notification center. * * @param context/*from w ww.jav a 2 s . c o m*/ * Application context * @param intent * Received intent with content data */ @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); JSONObject options; try { String data = bundle.getString(Options.EXTRA); options = new JSONObject(data); } catch (JSONException e) { e.printStackTrace(); return; } NotificationWrapper notification = new Builder(context, options).build(); onClear(notification); }