I am trying to pick an image from the Android Gallery only, not other applications like Photos, file manager etc
I need a solution to open the Gallery App directly, or is it possible to use the Photos Application to pick image?
1) Choose from gallery
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent,CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
2) onActivityResult result code
try {
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger images
options.inSampleSize = 2;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
descimage.setImageBitmap(bitmap);
bitmap.compress(CompressFormat.JPEG, 80, new FileOutputStream(new File(fileUri.getPath())));
photostatus = 1;
pbar.setVisibility(View.VISIBLE);
txtbrowser.setEnabled(false);
new upload().execute();
} catch (NullPointerException e) {
e.printStackTrace();
}
You should be aware that Gallery no longer exists on some devices running Lollipop. The photos app is the replacement and it should have no problems handling the intent to select an image.
Intent.ACTION_GET_CONTENT
is usually recommended for selecting images, such as:Opening the gallery on devices that do have it installed is discussed here. Basically every different vendor may ship a different gallery app.
It is possible to launch a specific activity for an implicit intent (such as selecting an image) without showing the chooser dialog by using the PackageManager.queryIntentActivities() API to iterate all the available packages on the users device so you can explicitly launch the one you require.