6

http://www.isco.com/webproductimages/appBnr/bnr1.jpg

I've used a website to see the metadata of a image. In this website, it shows all info of image. I want to know how to get the "Title" tag of above image in android.

I found here the similiar question for iOS only: How to get image metadata in ios

However I don't know how to get "Meta data" of image on android. ExifInterface only gives some informations. But I'm unable to get "Title" tag with it.

Can you provide any code snippet for get meta data in android for image?

Community
  • 1
  • 1
RVG
  • 3,538
  • 4
  • 37
  • 64

3 Answers3

10

Download metadata extractor from the link given here ...... click to download the library choose the version 2.5.0.RC-3.zip

Extract the jar Folder

and import jar into libs folder in your poject and then execute the below code

        try {
            InputStream is = new URL("your image url").openStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            Metadata metadata = ImageMetadataReader.readMetadata(bis,true);


    for (Directory directory : metadata.getDirectories()) {
    for (Tag tag : directory.getTags()) {
        System.out.println(tag);
    }
 }

            }
        catch (ImageProcessingException e){}
        catch (IOException e) {}
VENKI
  • 88
  • 2
  • 15
Venkatesh S
  • 5,466
  • 1
  • 25
  • 30
  • I've got a .jpg and it says `ImageProcessingException: File format is not supported`. I'm reading a .jpg image. Any idea on what's wrong? – Sonhja Jul 14 '15 at 09:05
  • This is the only thing that works for me to get picture orientation from iOS device on my android. Thanks ! – Damien R. Sep 21 '15 at 13:29
  • Works well with Kotlin. I just included implementation 'com.drewnoakes:metadata-extractor:2.18.0' in my grade app build file. – user3717478 Jan 22 '23 at 09:38
0

If you want to retrieve meta data information about an image ExifInterface is what you are looking for. Here is a quite good example of how this interface is used: http://android-er.blogspot.com/2009/12/read-exif-information-in-jpeg-file.html

But if you want to retrieve information of an online image I'm afraid it's not yet possible.

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
  • 1
    hi @korhanwzturk. thanks for reply. i've seen exifinterface, but it did nt get basic information of image like title. – RVG Sep 28 '12 at 04:16
  • 1
    Exif interface has its own limitations as well. Like it returns null value for corrupted images.Better avoid it. – maverick9888 Sep 12 '13 at 10:04
  • returning null for most of things only width and height is correct. – Nouman Ch Apr 12 '18 at 19:06
-1

If you want to retrieve metadata from image in Android project, then you can do that with the help of: https://github.com/drewnoakes/metadata-extractor

Implement this in your gradle using

implementation 'com.drewnoakes:metadata-extractor:2.12.0'

Complete code is as follows

private static String getImageMetaData(Uri image1) {
    try {
        InputStream inputStream = FILE_CONTEXT.getContentResolver().openInputStream(image1);
        try {
            image1.getEncodedUserInfo();
            Metadata metadata = ImageMetadataReader.readMetadata(inputStream);

            for (Directory directory1 : metadata.getDirectories()) {
                if (directory1.getName().equals("Exif IFD0")) {
                    for (Tag tag : directory1.getTags()) {
                        if (tag.getTagName().equals("Date/Time")) {
                            return tag.getDescription();
                        }
                    }
                }
            }
        } catch (ImageProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sahil Bansal
  • 609
  • 8
  • 6