Reputation: 3145
I am trying to extract location coordinates from image media in my Android app but ExifInterface providing a null value even though image media contains those details. I had tried on Android 9, 10, and 11 OS emulators and devices.
I am using android-image-picker library to provide image selection in my app. I believe that is not related to this image library.
I am also requesting ACCESS_MEDIA_LOCATION for Android 10 and later devices as documented here. I am still wondering if this is the case then it should work on an Android 9 device but no luck so far with that as well.
Please find image files here in dropbox to make sure they persist metadata details.
In debugging it shows attributes loaded in the ExifInterface object but when the app is trying to read it then it just returns null. Please take a look at debugging screenshot of the image (name: IMG_20210916_170621.jpg) from the above-shared images. The same image does show location details in the macOS Preview app as well as available Exif metadata reader websites (See screenshot below).
@Parcelize
data class Image(override val url: String) : LocalMedia(url) {
override fun toString(): String {
return url
}
fun readLatLong(): Pair<Double, Double>? {
try {
val exifInterface = ExifInterface(url)
exifInterface.latLong?.let {
if (it.size == 2) {
return Pair(it.first(), it.last())
}
}
} catch (e: Exception) {
Timber.e(e, "Reading latLong failed")
}
return null
}
}
I hope I am not misinterpreting anything here.
Upvotes: 3
Views: 1046