Android: Getting all existing exif data from an image
android, exif
Solution
you can make an array of all tags that you wish to query, and put the non-null results of the query into a collection (maybe hashmap) or something else (maybe JsonObject).
Example in Kotlin:
val pathToImage = "..."
val exif = ExifInterface(pathToImage)
val tagsToCheck = arrayOf(
ExifInterface.TAG_DATETIME,
ExifInterface.TAG_GPS_LATITUDE,
ExifInterface.TAG_GPS_LONGITUDE,
ExifInterface.TAG_EXPOSURE_TIME
)
val hashMap = HashMap<String, String>()
for (tag in tagsToCheck)
exif.getAttribute(tag)?.let { hashMap[tag] = it }
Problem
I know it's possible to get specific exif data by specifying the string tag in the ExifInterface. For example, getting the date of an image would be something like: ``` ExifInterface exif = new ExifInterface(pathToImage); exif.getAttribute(ExifInterface.TAG_DATETIME); ``` Is there a way to simply get all of the non-null available exif strings without having to manually write the get code for each of them?