我的应用程序将.jpg文件移动到其他文件夹,要在库存图库中查看,我有sendBroadcast ACTION_MEDIA_MOUNTED
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
Environment.getExternalStorageDirectory() ))); 但是这要花很多时间..我知道(也许)我必须在mediaStore中直接使用cursor/contentResolver手动更新,以获得更快的更新速度。有人能在这方面帮我吗?谢谢..我的代码实际上是:
Uri uri = (Uri) list.get(cont);
Cursor cursor = managedQuery(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String app = cursor.getString(column_index);
File orig = new File( app.toString());
File dest = new File( destination_path +"/"+ orig.getName().toString());
orig.renameTo(dest);这样,我将一个文件从一个路径移动到另一个路径。
在此之后,为了在图库中获取图像,我必须sendBroadcast ACTION_MEDIA_MOUNTED
发布于 2015-10-08 17:18:56
我只需要做同样的事情,使用下面的命令更新MediaStore
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, newPath);
boolean successMediaStore = context.getContentResolver().update(
MediaStore.<TYPE>.Media.EXTERNAL_CONTENT_URI, values,
MediaStore.MediaColumns.DATA + "='" + oldPath + "'", null) == 1;将<TYPE>替换为正确的媒体存储...(Images,Video,Audio...)
发布于 2012-08-11 01:34:12
使用MediaScannerConnection更新操作系统:
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
// code to execute when scanning is complete
}
});https://stackoverflow.com/questions/11906490
复制相似问题