通知图像移动到另一个文件夹 [英] notify image moved to another folder

查看:192
本文介绍了通知图像移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者的Andr​​oid程序员。我创建的隐藏图像的项目。但是,我有我的项目的问题。就是它:
我用的方法从文件夹 A 移动照片文件夹 .B (这是我如何把它藏在从图片库)。我相信,在文件夹中的图片 A 被删除并移动到文件夹 .B 。然而,当我打开图片库应用程序我依然看到这张照片是在文件夹 A 显示。

I am a beginner android programmer. I create a project for hiding image. But, I have a problem in my project. Is that: I use a method to move a photo from the folder A to folder .B(Here is how I hid it from image gallery) . I am sure that the picture in the folder A was deleted and moved to folder .B. However, when I open image gallery application I still see this picture is displayed at the folder A.

这是一份方法图片​​文件夹 .B

This is method copy picture to folder .B:

    public static String copyFile(String path) {
        //TO DO: create folder .B

        File pathFrom = new File(path);
        File pathTo = new File(Environment.getExternalStorageDirectory() + "/.B");
        File file = new File(pathTo, fileToName);

        while (file.exists()) {
            fileToName = String.valueOf(System.currentTimeMillis());
            file = new File(pathTo, fileToName);
        }

        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(pathFrom);
            out = new FileOutputStream(file);

            byte[] data = new byte[in.available()];
            in.read(data);
            out.write(data);
            in.close();
            out.close();

            return file.getPath();
        } catch (FileNotFoundException e) {
            Log.e(TAG, e.getMessage());
            return "error:" + e.getMessage();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
            return "error:" + e.getMessage();
        }
    }

在复制图片到文件夹 .B ,我删除了这张照片文件夹 A

After copy picture to folder .B, I delete this picture in folder A:

new File(path).delete();

所以,是否有通知所有图片廊任何建议知道,这幅画被转移到另一个文件夹或另一个URI?

So Is there any suggestion for notify for all image gallery know that this picture was moved to another folder or another URI?

**更新:我的建议做工精细是:
4.4前,你可以调用这个:

**UPDATE: The suggestion for me work fine is: Before 4.4,you can call this:

sendBroadcast(新<$c$c>Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse(\"file://\"+Environment.getExternalStorageDirectory())));
4.4后,试试这个:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory()))); After 4.4,try this:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));

//该文件是新形象的道路。

//the file is new image's path

感谢FireSun和everyonce

THank FireSun and everyonce

推荐答案

变化imgae路径后,应通知库进行更新,所以你应该发送广播做出来。


4.4前,你可以调用这个:

After change imgae path,you should notify the gallery to update,so you should send a broadcast to make it.
Before 4.4,you can call this:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));  

4.4后,试试这个:

After 4.4,try this:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
//the file is new image's path

这篇关于通知图像移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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