getLatLong 始终 returns 错误

getLatLong always returns false

我正在尝试使用 android.media.ExifInterface 库从地理标记图像中检索经度和纬度值。然而,getLatLong 总是 returns false 尽管图像是地理标记的。这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button galleryButton = (Button) findViewById(R.id.galleryButton);

    galleryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           Intent pickPhoto = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(pickPhoto , 1);


        }

    });


}


protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {

    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case 0:
            if(resultCode == RESULT_OK){
                Uri selectedImage = imageReturnedIntent.getData();
                ExifInterface exif = new ExInterface(selectedImage.getPath());
                float[] latlong = null;
                bool result = exif.getLatLong(latlong);


            }

            break;

    }
}

如您所见,我正在使用返回的 URI 的路径初始化 exif 对象,它包含类似于“/external/images/media/2330”的路径。当我调用 getLatLong 时,它总是 returns false。我也尝试了 this page 中的示例,但仍然不起作用。任何帮助将不胜感激。

银河 S6 边缘 Android SDK 版本 25

getPath() 仅适用于具有 file 方案的 Uri。你有一个 content 方案。另外,您使用的 ExifInterface 存在安全漏洞。

com.android.support:exifinterface:25.3.1 库添加到您的 dependencies

接下来,将您的 android.media.ExifInterface 导入替换为 android.support.media.ExifInterface

然后,替换:

ExifInterface exif = new ExInterface(selectedImage.getPath());

与:

ExifInterface exif = new ExifInterface(getContentResolver().openInputStream(selectedImage));