List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.cordova.photo.CameraLauncher.java
/** * Applies all needed transformation to the image received from the gallery. *//from www .ja va 2s. com * @param destType In which form should we return the image * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ private void processResultFromGallery(int destType, Intent intent) { Uri uri = intent.getData(); if (uri == null) { if (croppedUri != null) { uri = croppedUri; } else { this.failPicture("null data from photo library"); return; } } int rotate = 0; // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.activity); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); this.orientationCorrected = true; } catch (OutOfMemoryError oom) { this.orientationCorrected = false; } } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { // Did we modify the image? if ((this.targetHeight > 0 && this.targetWidth > 0) || (this.correctOrientation && this.orientationCorrected)) { try { String modifiedPath = this.ouputModifiedBitmap(bitmap, uri); // The modified image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.callbackContext .success("file://" + modifiedPath + "?" + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.callbackContext.success(uri.toString()); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } }
From source file:ca.ualberta.cmput301.t03.inventory.AddItemView.java
/** * Upon return from the gallery or the camera, we get the bitmap returned and add it to the item's * photoGallery model via the ItemPhotoController; this will ensure the photo gets sized correctly * * Code used:/*from w w w. ja v a2 s.c o m*/ * http://stackoverflow.com/questions/27874038/how-to-make-intent-chooser-for-camera-or-gallery-application-in-android-like-wha * @param requestCode We set this when launching the intent to determine how to handle its return * @param resultCode if the intent returned with what we want, this will be RESULT_OK * @param data optional data returned by the activity */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Bitmap tempImage = null; if (resultCode == RESULT_OK) { if (requestCode == REQUEST_IMAGE_CAPTURE) { File f = new File(Environment.getExternalStorageDirectory().toString()); for (File temp : f.listFiles()) { if (temp.getName().equals("temp.jpg")) { f = temp; break; } } try { tempImage = BitmapFactory.decodeFile(f.getAbsolutePath(), new BitmapFactory.Options()); f.delete(); } catch (Exception e) { e.printStackTrace(); } } else if (requestCode == SELECT_FILE) { Uri selectedImageUri = data.getData(); String tempPath = getPath(selectedImageUri, AddItemView.this); tempImage = BitmapFactory.decodeFile(tempPath, new BitmapFactory.Options()); } } final Bitmap image = tempImage; if (tempImage != null) { AsyncTask worker = new AsyncTask() { @Override protected Object doInBackground(Object[] params) { itemPhotoController.addPhotoToItem(image); return null; } }; worker.execute(); } }
From source file:com.poomoo.edao.activity.UploadPicsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == NONE) return;//from w w w. j a v a 2 s.co m // ? if (requestCode == PHOTOHRAPH) { System.out.println("?"); setImage(image_capture_path); } if (data == null) { System.out.println(""); return; } // ? if (requestCode == PHOTORESOULT) { // ?Uri,Uri???Uri?? Uri mImageCaptureUri = data.getData(); System.out.println("mImageCaptureUri:" + mImageCaptureUri); // Uri???Uri??? if (mImageCaptureUri != null) { try { String imagePath; Cursor cursor = getContentResolver().query(mImageCaptureUri, new String[] { Media.DATA }, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(Media.DATA); imagePath = cursor.getString(columnIndex); // ??? cursor.close(); setImage(imagePath); } catch (Exception e) { e.printStackTrace(); } } super.onActivityResult(requestCode, resultCode, data); } }
From source file:net.mutina.uclimb.ForegroundCameraLauncher.java
/** * Called when the camera view exits. /*w ww .j av a 2 s.c o m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); exif.createInFile(getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.ctx.getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { uri = this.ctx.getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.ctx.getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } // Add compressed version of captured image to returned media store Uri OutputStream os = this.ctx.getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.ctx)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PERFORM_ACTIONS: mActivityCallback.onFinished();/* ww w . j ava2s.c o m*/ break; case ACTIVITY_REQUEST_FILE: if (data != null && resultCode == Activity.RESULT_OK) { mSelectedUri = data.getData(); GenericProgressDialog.Builder builder = new GenericProgressDialog.Builder(); builder.title(R.string.in_app_flashing_dialog_verifying_zip); builder.message(R.string.please_wait); builder.build().show(getFragmentManager(), PROGRESS_DIALOG_VERIFY_ZIP); queryUriMetadata(); } break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.piusvelte.sonet.core.SonetCreatePost.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PHOTO://from w ww .j a v a 2 s.c om if (resultCode == RESULT_OK) { getPhoto(data.getData()); } break; case TAGS: if ((resultCode == RESULT_OK) && data.hasExtra(Stags) && data.hasExtra(Accounts.SID)) mAccountsTags.put(data.getLongExtra(Accounts.SID, Sonet.INVALID_ACCOUNT_ID), data.getStringArrayExtra(Stags)); break; } }
From source file:ca.mudar.parkcatcher.ui.activities.MainActivity.java
@Override public void onResume() { super.onResume(); // Check Playservices status if (isPlayservicesOutdated) { if (GooglePlayServicesUtil .isGooglePlayServicesAvailable(getApplicationContext()) != ConnectionResult.SUCCESS) { // Still out of date, interrupt onResume() disableLocationUpdates();// ww w .j a va2s . c o m } else { // Playservice updated, display message and restart activity parkingApp.showToastText(R.string.toast_playservices_restart, Toast.LENGTH_LONG); final Intent intent = getIntent(); this.finish(); startActivity(intent); } return; } if (!ConnectionHelper.hasConnection(this)) { ConnectionHelper.showDialogNoConnection(this); } // TODO Optimize this using savedInstanceState to avoid reload of // identical data onResume final Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { updateParkingTimeFromUri(intent.getData()); updateParkingTimeTitle(); updateParkingDateButton(); updateParkingTimeButton(); updateParkingDurationButton(); mFavoritesFragment.refreshList(); } // if // (getSupportActionBar().getSelectedTab().getTag().equals(Const.TAG_TABS_MAP) // || isCenterOnMyLocation) { if (initLocation != null || isCenterOnMyLocation) { try { mMapFragment.setMapCenter(initLocation); isCenterOnMyLocation = false; final ActionBar ab = getSupportActionBar(); if (ab.getSelectedTab().getPosition() != Const.TABS_INDEX_MAP) { ab.setSelectedNavigationItem(Const.TABS_INDEX_MAP); } } catch (NullPointerException e) { e.printStackTrace(); } } // } }
From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); switch (requestCode) { case Constants.ACTIVITY_PICK_SUBREDDIT: if (resultCode == Activity.RESULT_OK) { // Group 1: Subreddit. final Pattern REDDIT_PATH_PATTERN = Pattern.compile(Constants.REDDIT_PATH_PATTERN_STRING); Matcher redditContextMatcher = REDDIT_PATH_PATTERN.matcher(intent.getData().getPath()); if (redditContextMatcher.find()) { String newSubreddit = redditContextMatcher.group(1); final EditText linkSubreddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText textSubreddit = (EditText) findViewById(R.id.submit_text_reddit); if (newSubreddit != null) { linkSubreddit.setText(newSubreddit); textSubreddit.setText(newSubreddit); } else { linkSubreddit.setText(""); textSubreddit.setText(""); }/* w w w.j a va 2 s .c o m*/ } } break; default: break; } }
From source file:com.lepin.activity.CarDriverVerify.java
/** * TODO// w w w .j a va 2 s.c om */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode != Activity.RESULT_OK) return; Bitmap bitmap = null; if (requestCode == CAMERA_RESULT) { path = util.getPath(carId, PhoteName[i], CarDriverVerify.this); bitmap = Util.getInstance().getSmallBitmap(CarDriverVerify.this, path); boolean flag = Util.getInstance().save(CarDriverVerify.this, path, bitmap); } else if (requestCode == IMAGE_RESULT) { Uri selectedImage = data.getData(); if (!String.valueOf(selectedImage).startsWith("content:")) { Util.showToast(CarDriverVerify.this, "??"); } else { path = Util.getInstance().getImagePath(CarDriverVerify.this, selectedImage); bitmap = Util.getInstance().getSmallBitmap(CarDriverVerify.this, path); Util.getInstance().save(CarDriverVerify.this, pathString[i], bitmap); } } if (null != bitmap) { imageViews[i].setImageBitmap(bitmap); } }
From source file:com.hackensack.umc.activity.ProfileActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_IMAGE_CAPTURE: if (resultCode == RESULT_OK) { try { if (data != null) { imageUri = data.getData(); setImageToImageView(imageUri); }/*w w w . j av a2s . co m*/ } catch (Exception e) { e.printStackTrace(); } } break; case RESULT_GALLERY: if (resultCode == RESULT_OK) { try { if (data != null) { imageUri = data.getData(); Log.v(TAG, "imageUri::" + imageUri); setImageToImageView(imageUri); } } catch (Exception e) { e.printStackTrace(); } } break; } }