ExifData已保存,但图库详细信息未更新

时间:2018-01-09 17:45:43

标签: android exif

我有一个应用程序,其中可视化我拍摄的一些照片的元数据,我可以使用Place Picker编辑位置并更新 exif 使用以下代码的数据:

                ExifInterface exifInterface = null;
                try {
                    exifInterface = new ExifInterface(imageFile.getAbsolutePath());
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if(exifInterface != null) {
                    try {

                        exifInterface.setLatLong(place.getLatLng().latitude,place.getLatLng().longitude);
                        exifInterface.saveAttributes();
                        sendBroadcastToUpdateMediaFile();
                        Log.v(TAG,"Updating with: "+place.getName());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

数据确实获得了更新,因为如果我关闭应用并再次打开它并可视化Exif数据,我可以看到新的位置,但是如果我进入并点击相同图片上的详细信息,但该位置不存在。照片格式是 jpeg / jpg ,因为只有那些类型可以有exif数据(例如我在png上尝试添加 exifdata 时出错)。

为什么来自图库中同一图像的exif数据不会更新?我究竟做错了什么?

编辑:

解决方案:

private void sendBroadcastToUpdateMediaFile(){
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        File f = new File(imageFile.getAbsolutePath());
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);
    }

1 个答案:

答案 0 :(得分:0)

为了让MediaStore收到您刚刚对照片进行更新的通知,您必须使用MediaScanner发送广播并扫描照片。

private void sendBroadcastToUpdateMediaFile(){
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            File f = new File(imageFile.getAbsolutePath());
            Uri contentUri = Uri.fromFile(f);
            mediaScanIntent.setData(contentUri);
            this.sendBroadcast(mediaScanIntent);
        }
相关问题