0

I was searching for how to I can identify or check if the file selected by the user is an Image (eg of extension: .jpg or .png or .bmp and more). Note that the image is not just one file it's list of images.
I've tried this code:

final File folder = new File( oo );
final File[] listOfFiles = folder.listFiles();
ImageView imageView = new ImageView();
String mimeType = new MimetypesFileTypeMap().getContentType( folder );
String type = mimeType.split( "/" )[0].toLowerCase();
if ( !type.equals( "image" ) ) {
    //TODO
}
else {
    //TODO
}

After trying that code nothing changed i still get the problem. How i can do so and thanks a lot :-)

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
A_A
  • 11
  • 6

2 Answers2

0

What do you expect to get from getContentType if you pass in the folder instead of a file from the listOfFiles?

mipa
  • 10,369
  • 2
  • 16
  • 35
0

You have to loop over all files of the array "listOfFiles" and check the mime of each entry. I would suggest that you add a boolean flag which you start with true. If you find one file that isn't an image, you set the flag to false. If the flag is still true after the loop, you can continue. Otherwise, you show an error dialog.

ZetQ
  • 51
  • 4