Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update gallery after moving photo programmatically?

I am moving photo from on directory to another using following code

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())));
 }

photos moved to new directory successfully but it take too long time when photos are more in count to update gallery and gallery updates after around 30 seconds or more So give me suggestion what I should do if logic to update file using sendBroadcast is wrong?

Thanks.

like image 526
kiran boghra Avatar asked Nov 15 '13 12:11

kiran boghra


2 Answers

to remove from gallery

try {

  getContentResolver().delete();

   } catch (Exception e) {
        e.printStackTrace();
   }
like image 191
kiran boghra Avatar answered Sep 24 '22 22:09

kiran boghra


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);
                        }
                    });
}
like image 20
Manoj Baria Avatar answered Sep 22 '22 22:09

Manoj Baria