经过照片如何更新Android的画廊? [英] How can I update the Android Gallery after a photo?

查看:126
本文介绍了经过照片如何更新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)));

这篇关于经过照片如何更新Android的画廊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆