How to get photo metadata from Android

Asked 2 years ago, Updated 2 years ago, 118 views

As far as I know, photos have metadata like music files. I heard that the size, pixel, and date of the picture are saved. I'd like to get the price of the date I took the picture, so how can I get it?

image android exif metadata

2022-09-22 22:15

1 Answers

A class called ExifInterface on Android supports this feature.

String filename = "Path to file";
try {
    ExifInterface exif = new ExifInterface(filename);
    showExif(exif);
} } catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(this, "Error!", Toast.LENGTH_LONG).show();
}

When using ExifInterface, you must make an exception.

private void showExif(ExifInterface exif) {

    String myAttribute = "[Exif information] \n\n";

    myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif);
    myAttribute += getTagString(ExifInterface.TAG_FLASH, exif);
    myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE, exif);
    myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE_REF, exif);
    myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif);
    myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE_REF, exif);
    myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH, exif);
    myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH, exif);
    myAttribute += getTagString(ExifInterface.TAG_MAKE, exif);
    myAttribute += getTagString(ExifInterface.TAG_MODEL, exif);
    myAttribute += getTagString(ExifInterface.TAG_ORIENTATION, exif);
    myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE, exif);

    mView.setText(myAttribute);
}

You can get the value of that tag in this way. Here If you want to get the date, you can use ExifInterface.TAG_DATETIME.


2022-09-22 22:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.