Android 如何在以编程方式移动照片后更新图库?
我正在使用以下代码将照片从一个目录移动到另一个目录Android 如何在以编程方式移动照片后更新图库?,android,photo-gallery,Android,Photo Gallery,我正在使用以下代码将照片从一个目录移动到另一个目录 File oldfile= new File(originalImagePath); File newfile=new File(newImagePath); boolean d=oldfile.renameTo(newfilee); if(d){ sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + newfilee
File oldfile= new File(originalImagePath);
File newfile=new File(newImagePath);
boolean d=oldfile.renameTo(newfilee);
if(d){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + newfilee.getPath())));
}
照片已成功移动到新目录,但当照片数量较多时,大约30秒或更长时间后更新图库和图库更新会花费太长时间,因此请给出建议,如果使用sendBroadcast更新文件的逻辑错误,我应该怎么做
谢谢 从库中删除
try {
getContentResolver().delete();
} catch (Exception e) {
e.printStackTrace();
}
if(Build.VERSION.SDK\u INT<19)
mContext.sendBroadcast(新意图(
意图.行动\媒体\安装,
parse(“文件://”
+getExternalStorageDirectory());
否则{
MediaScannerConnection
.scanFile(
McContext,
新字符串[]{imageFile.toString()},
无效的
新的MediaScannerConnection.OnScanCompletedListener(){
已完成的公众假期(
字符串路径(Uri){
Log.i(“外部存储”、“扫描”
+路径+“:”;
Log.i(“外部存储”,“->uri=”
+uri);
}
});
}
Hi,谢谢,可以将Uri.parse(..)替换为插入图像的Uri:java getActivity().getContentResolver().notifyChange(Uri,null)代码>欢迎,是的,您也可以传递插入图像的uri。我想添加一个简短的解释,说明为什么或如何帮助。对我来说很有用。。谢谢!!:-)
if (Build.VERSION.SDK_INT < 19)
mContext.sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
else {
MediaScannerConnection
.scanFile(
mContext,
new String[]{imageFile.toString()},
null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(
String path, Uri uri) {
Log.i("ExternalStorage", "Scanned "
+ path + ":");
Log.i("ExternalStorage", "-> uri="
+ uri);
}
});
}