我的问题是Android 10无法从jpeg文件中读取GPS信息。同样的文件在Android9上运行,我尝试了返回null的ExifInterface (androidx),以及,它表示"GPSLatitude:无效的rational (0/0),无效的rational (0/0)“。其他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;
}
在Android /10上,所有getAttribute调用都返回null,而在Android9上,它正在工作。我的测试照片确实包含GPS信息。就连Android本身也无法将GPS定位到他们的媒体商店中。该字段在他们的数据库中也是空的。我通过邮件传送了测试照片。
发布于 2019-09-17 19:58:16
正如前面提到的,现在,在Android10上,嵌入到图像文件中的位置不能直接提供给应用程序:
但是,由于这个位置信息是敏感的,所以Android 10在默认情况下会在应用程序中隐藏这些信息,如果它使用作用域存储的话。
在相同的链接上,您可以检查如何修复:
ACCESS_MEDIA_LOCATION
许可。setRequireOriginal()
,传入照片的URI,如下面的代码片段所示:代码片段:
Uri photoUri = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
cursor.getString(idColumnIndex));
// Get location data from the ExifInterface class.
photoUri = MediaStore.setRequireOriginal(photoUri);
InputStream stream = getContentResolver().openInputStream(photoUri);
if (stream != null) {
ExifInterface exifInterface = new ExifInterface(stream);
// Don't reuse the stream associated with the instance of "ExifInterface".
stream.close();
} else {
// Failed to load the stream, so return the coordinates (0, 0).
latLong = new double[2];
}
注意他们现在是如何使用Uri
、InputStream
(以及FileDescriptor
)来访问文件的,因为现在您不能使用它的文件路径访问文件。
https://stackoverflow.com/questions/57980935
复制相似问题