通知图像移动到另一个文件夹
notify image moved to another folder
我是初学者 android 程序员。我创建了一个隐藏图像的项目。但是,我的项目有问题。就是它:
我使用一种方法将照片从文件夹 A
移动到文件夹 .B
(这是我从图片库中隐藏它的方法)。我确定文件夹 A
中的图片已被删除并移动到文件夹 .B
。但是,当我打开图片库应用程序时,我仍然看到这张图片显示在文件夹 A
.
中
这是复制图片到文件夹的方法.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
中删除了这张图片:
new File(path).delete();
那么有没有建议通知所有图片库知道这张照片已移动到另一个文件夹或另一个 URI?
**更新:对我来说工作正常的建议是:
在 4.4 之前,你可以这样调用:
发送广播(新Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));
4.4 之后,试试这个:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
//文件是新图片的路径
感谢 FireSun 和大家
你为什么不用
pathFrom.delete();
修改imgae路径后,需要通知图库更新,所以需要发送广播才能完成。
在 4.4 之前,你可以这样调用:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));
4.4 之后,试试这个:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
//the file is new image's path
我是初学者 android 程序员。我创建了一个隐藏图像的项目。但是,我的项目有问题。就是它:
我使用一种方法将照片从文件夹 A
移动到文件夹 .B
(这是我从图片库中隐藏它的方法)。我确定文件夹 A
中的图片已被删除并移动到文件夹 .B
。但是,当我打开图片库应用程序时,我仍然看到这张图片显示在文件夹 A
.
这是复制图片到文件夹的方法.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
中删除了这张图片:
new File(path).delete();
那么有没有建议通知所有图片库知道这张照片已移动到另一个文件夹或另一个 URI?
**更新:对我来说工作正常的建议是: 在 4.4 之前,你可以这样调用:
发送广播(新Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));
4.4 之后,试试这个:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
//文件是新图片的路径
感谢 FireSun 和大家
你为什么不用
pathFrom.delete();
修改imgae路径后,需要通知图库更新,所以需要发送广播才能完成。
在 4.4 之前,你可以这样调用:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));
4.4 之后,试试这个:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
//the file is new image's path