Reputation: 81
my app move .jpg file to others folders and to get viewable in the stock gallery i have sendBroadcast ACTION_MEDIA_MOUNTED
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
Environment.getExternalStorageDirectory() )));
but this take much time.. i have understand (maybe) that i have to update manually with cursor/contentResolver in mediaStore directly to get this faster. can anyone help me on this? thanks.. my code actually is:
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);
with this i move a file from a path to another one.
after this, to get images in gallery i have to sendBroadcast ACTION_MEDIA_MOUNTED
Upvotes: 5
Views: 4564
Reputation: 17848
I just had to do the same, use following to update the 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;
Replace <TYPE>
with the correct media store... (Images
, Video
, Audio
...)
Upvotes: 4
Reputation: 17810
Use the MediaScannerConnection to update the OS:
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
}
});
Upvotes: 0