I'm developing an Android app where a user has to select an image from the gallery. This image should have either .jpeg/.png extension.
I have tried:
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/jpeg, image/png");
However, it still allows me to select .gif images. What am I doing wrong?
Intent sharingIntent = new Intent(Intent. ACTION_SEND); Uri imageUri = Uri. parse("http://stacktoheap.com/images/stackoverflow.png"); sharingIntent. setType("image/png"); sharingIntent.
Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.
Your code should look like this, if you want to specify the image formats that you want to allow:
String[] mimeTypes = {"image/jpeg", "image/png"};
final Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
.setType("image/*")
.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With