Getting an image from the Gallery with
Intent intentGallery = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGallery, CHOOSE_PICTURE);
and
Uri targetUri = data.getData();
Log.v(LOG_TAG,"Data achieved from gallery: "+ targetUri);
results in content://com.android.sec.gallery3d.provider/picasa/ if the user selected a Picasa image.
This solution is not good for me, because i don't want to use internet.
So, there is a way to pick only the local picasa image thumbnail from gallery?
Related
I'm facing a problem that I cannot solve. I would be grateful if you could help me.
I would like to make an app that picks one or more images from the gallery, elaborates them and saves them into a folder.
The problem I have is to rotate the images correctly.
When I pick one image (see the code below), the app rotates the image correctly.
If I pick more images simultaneously (see the code below) I cannot rotate them because the value of "rotation" (see the code below) is always 0 (zero).
To pick one image from the gallery, I use the following code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG);
In "OnActivityResult" I get the URI path as following:
Uri imageUri = data.getData();
To pick more images I use the following code (that doesn’t open the gallery, just the recent images, but it’s acceptable for me):
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
In "OnActivityResult" I get the URI path as following:
ClipData mClipData = data.getClipData();
and in a "for":
ClipData.Item item = mClipData.getItemAt(i);
Uri imageUri = item.getUri();
To get the image orientation I use the following code:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = getApplicationContext().getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Note: I tried to use the “ExifInterface” class but it always returns 0 (zero) on my Samsung S7 Android 7.0.
I noticed that the method to pick one image returns a URI path like “content://media/external/images/media/imageX”, instead the method to pick more images returns a URI path like “content://com.android.providers.media.documents/document/imageX”. I don’t know if it can be the problem.
Thank you everybody in advance.
Vincenzo
I want to open device gallery except .gif images.
I tried the following code but it showing all images in gallery, let me help
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(Build.VERSION.SDK_INT >21){
pickPhoto.setType("image/*");
pickPhoto.setAction(Intent.ACTION_GET_CONTENT);
}
startActivityForResult(pickPhoto, PICK_FROM_GALLERY);
To open the device gallery except for .gif images, you need to set the supported mimeTypes for the gallery intent i.e., image types you need to pick from the gallery like png, jpg, jpeg, etc.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
String[] mimeTypes = {"image/png", "image/jpg", "image/jpeg"};
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_GALLERY);
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:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, ID);
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.
This intent allows you to pick the image from the default gallery.
// in onCreate or any event where your want the user to select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
For receiving the selected image in onActivityResult()
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
i got the solution from here
I am working on Android application in which I want to pass image from gallery. Previously my code take image from drawable and send it to cropping class. Now I want to use my gallery pic which I have selected instead of R.id.cropImg.
My code for gallery image with URI is also given below:
// for image gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
// OnActivity
if (requestCode == SELECT_PICTURE) {
final Uri selectedImageUri = data.getData();
//showLoadingDialog();
if (Build.VERSION.SDK_INT < 19) {
selectedImagePath = getPath(selectedImageUri);
int index=1;
mIntent.putExtra("index", index);
startActivityForResult(mIntent, requestCode);
}
}
// now I want to give the location of my image in place
// of R.id.cropImg
setContentView(R.layout.fragment_cropimage);
final CropImageView mCropImage = (CropImageView)findViewById(R.id.cropImg);
mCropImage.setDrawable(getResources().getDrawable(R.drawable.precrop),300,300);
// Before galley it was taking img from drawable for
// cropping, now I want from gallery.
I want to upload photos from Android's mobile gallery from my app. How can I do that?
You should use the MediaStore to be able to get pictures from the gallery:
http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html
Edit:You can get the image with this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1);
And you get the bitmap with this in your onActivityResult :
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), data.getData());