ExifData 已保存但图库图像详细信息未更新
ExifData gets saved but gallery image details are not updated
我有一个应用程序,我可以在其中 可视化 我拍摄的一些照片的元数据,我可以使用 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 数据,我可以看到新的 location 在那里,但如果我进去图库 并单击同一图像上的详细信息位置不存在。照片格式是 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);
}
为了让 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);
}
我有一个应用程序,我可以在其中 可视化 我拍摄的一些照片的元数据,我可以使用 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 数据,我可以看到新的 location 在那里,但如果我进去图库 并单击同一图像上的详细信息位置不存在。照片格式是 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);
}
为了让 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);
}