我遇到了 Android 10 无法从我的 jpeg 文件中读取 GPS 信息的问题。完全相同的文件在 Android 9 上运行。我尝试了返回 null 的 ExifInterface (androidx),以及显示“GPSLatitude:无效的理性 (0/0),无效的理性 (0/0)”的 apache commons 成像。其他 exif 信息(如评级或 XPKeywords)被正确读取。
如何解决?
测试代码:
import androidx.exifinterface.media.ExifInterface;
ExifInterface exif2 = new ExifInterface(is);
double[] latLngArray = exif2.getLatLong();
getLatLong 实现:
public double[] getLatLong() {
String latValue = getAttribute(TAG_GPS_LATITUDE);
String latRef = getAttribute(TAG_GPS_LATITUDE_REF);
String lngValue = getAttribute(TAG_GPS_LONGITUDE);
String lngRef = getAttribute(TAG_GPS_LONGITUDE_REF);
if (latValue != null && latRef != null && lngValue != null && lngRef != null) {
try {
double latitude = convertRationalLatLonToDouble(latValue, latRef);
double longitude = convertRationalLatLonToDouble(lngValue, lngRef);
return new double[] {latitude, longitude};
} catch (IllegalArgumentException e) {
Log.w(TAG, "Latitude/longitude values are not parseable. " +
String.format("latValue=%s, latRef=%s, lngValue=%s, lngRef=%s",
latValue, latRef, lngValue, lngRef));
}
}
return null;
}
所有 getAttribute 调用在 Android Q/10 上都返回 null。在 Android 9 上它正在运行。我的测试照片确实包含 GPS 信息。甚至 Android 本身也无法将 GPS 位置索引到他们的媒体存储中。该字段在他们的数据库中也是空的。我通过邮件传送了测试照片。