Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIME type images/* is showing images and videos both

I am trying to get the images from sd card using Intent. Below is my code:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);

When I am running my app on samsung it's shows images to select but when I run the same code on Micromax it's showing images as well as videos.

I want to select only images. How can I solve this problem?

like image 487
Nitesh Kumar Avatar asked Apr 21 '14 10:04

Nitesh Kumar


2 Answers

I solved this problem by checking the extension of the file I am receiving and if the received file's extension is a video file's extension then I am showing user a Toast to select only photo.

Below is the method I used to get the file's extension

public static String getImageExtensionFromPath(String imagePath) {
    String[] imageNameArray = imagePath.split("/");
    String imageName = imageNameArray[imageNameArray.length - 1];
    String[] imageArray = imageName.split("\\.");
    String finalImageName = imageArray[1];
    return finalImageName;
}
like image 112
Nitesh Kumar Avatar answered Nov 15 '22 03:11

Nitesh Kumar


Add this in your AndroidManifest.xml

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
</intent-filter>

Add intent-filter into your specific listed activity. check this Google Code

like image 20
Jaykumar Patel Avatar answered Nov 15 '22 02:11

Jaykumar Patel