首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓Q/10上没有读取ExifInterface全球定位系统

安卓Q/10上没有读取ExifInterface全球定位系统
EN

Stack Overflow用户
提问于 2019-09-17 19:33:46
回答 1查看 3.2K关注 0票数 2

我的问题是Android 10无法从jpeg文件中读取GPS信息。同样的文件在Android9上运行,我尝试了返回null的ExifInterface (androidx),以及,它表示"GPSLatitude:无效的rational (0/0),无效的rational (0/0)“。其他exif信息,如评级或XPKeywords被正确读取。

怎么解决这个问题?

测试代码:

代码语言:javascript
运行
复制
import androidx.exifinterface.media.ExifInterface;
ExifInterface exif2 = new ExifInterface(is);
double[] latLngArray = exif2.getLatLong();

getLatLong实现:

代码语言:javascript
运行
复制
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定位到他们的媒体商店中。该字段在他们的数据库中也是空的。我通过邮件传送了测试照片。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-17 19:58:16

正如前面提到的,现在,在Android10上,嵌入到图像文件中的位置不能直接提供给应用程序:

但是,由于这个位置信息是敏感的,所以Android 10在默认情况下会在应用程序中隐藏这些信息,如果它使用作用域存储的话。

在相同的链接上,您可以检查如何修复:

  1. 在应用程序清单中请求ACCESS_MEDIA_LOCATION许可。
  2. 从您的MediaStore对象调用setRequireOriginal(),传入照片的URI,如下面的代码片段所示:

代码片段:

代码语言:javascript
运行
复制
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];
}

注意他们现在是如何使用UriInputStream (以及FileDescriptor)来访问文件的,因为现在您不能使用它的文件路径访问文件。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57980935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档