I am trying to get the image I am getting back at onActivityResult after picking an image at ACTION_GET_CONTENT system intent. I am using the doc's 'setPic()' method in order to reduce the image size but for some reason I get nothing when using the method. Here are my Intent, onActivityResulty and setPic() methods -
private void requestPickingPhoto() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, PICK_VIDEO_REQUEST_CODE);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_VIDEO_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri originalDataUri = data.getData();
cachedLocalImageUri = originalDataUri;
Timber.d("Receive image from: %s", originalDataUri);
mImageSent.setImageURI(cachedLocalImageUri);
setPic(originalDataUri.toString(), mImageSent);
}
}
private void setPic(String imagePath, ImageView destination) {
int targetW = destination.getWidth();
int targetH = destination.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = (int) Math.sqrt(Math.min(photoW/targetW, photoH/targetH));
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, bmOptions);
destination.setImageBitmap(bitmap);
}
my goal is to use the Uri I am getting back from the intent in order to reduce the image resolution dramaticly so I can use it for firebase cloud messaging rich notification which is size limited.