根据官方文档,我试图在android中重新创建一个可以访问本地图像元数据的函数。
这是代码(取自https://developer.android.com/preview/privacy/scoped-storage#media-from-native-code)
Uri photoUri = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
cursor.getString(idColumnIndex)); //errors
final double[] latLong;
// Get location data from the ExifInterface class.
photoUri = MediaStore.setRequireOriginal(photoUri);
InputStream stream = getContentResolver().openInputStream(photoUri);
if (stream != null) {
ExifInterface exifInterface = new ExifInterface(stream);
double[] returnedLatLong = exifInterface.getLatLong();
// If lat/long is null, fall back to the coordinates (0, 0).
latLong = returnedLatLong != null ? returnedLatLong : new double[2];
// 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];
}
Android Studio在“ cursor.getString”上出错,其余的失败。 另外,如何使用此示例代码来实现图像的硬编码路径?
我们将不胜感激任何帮助。
答案 0 :(得分:0)
尝试:
Uri photoUri = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
cursor.getString(String.valueOf(idColumnIndex));
或:
cursor.getInt(idColumnIndex);