经过照片如何更新Android的画廊?
对于大学,我发展与面部检测在Android上的应用程序。 对于这个我已经保存各种照片我的画廊。 问题是,在保存照片后,画廊不更新。 更多precisely,如果我删除,我要去哪里保存图像的目录,我打开应用程序和拍摄的照片,然后进入画廊和一个更新我看到后的照片。 但是,一旦我有目录,如果我拍一张新照片,这并不能覆盖旧的。
For the university i've to develop an application on android with the face detections. For this i've to save various photo on my gallery. The problem is that after saving the photo, the gallery do not update. More precisely, if I delete the directory where I'm going to save the image, I open the application and shoot the photo, then going into the gallery and after an "update" I see the photo. But once I have the directory, if I take a new picture, this did not overwrite the old one.
网上我找到这个:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://" + Environment.getExternalStorageDirectory())));
...但它不工作!
...but it doesn't work!
这是我的code:
.
.
.
ImageButton buttonPicture = (ImageButton) findViewById(R.id.camera_surface_button);
buttonPicture.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
mCamera.takePicture(null, null, jpegCallback);
//File file = new File(savedPath, "ing.jpg");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
});
.
.
.
.
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] _data, Camera _camera) {
imagesFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/TTRprova");
imagesFolder.mkdirs();
String fileName = "image3.jpg";
File output = new File(imagesFolder, fileName);
textView1.setText("-----Sono nella callback-----");
Uri outputFileUri = Uri.fromFile(output);
String filePath = outputFileUri.getPath();
File file= new File(filePath);
try {
FileOutputStream fos = new FileOutputStream(file, true);
fos.write(_data);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
textView1.setText("-----FileNotFoundException-----");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
textView1.setText("-----IOException-----");
e.printStackTrace();
}
//riparte la preview della camera
//mCamera.startPreview();
}
};
希望在您的帮助。 再见
Hope in your help. Bye
您可以强制MediaScanner添加特定文件(或让它知道它已被删除或修改)
You can force the MediaScanner to add a specific file (or let it know it was deleted or modified)
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(myNewFile)));