user3931951
user3931951

Reputation: 1

How to refresh gallery the in android kitkat?

How to refresh gallery the in android kitkat?

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

I tried with the above, but its not refreshing in android 4.4. How to refresh the gallery when add/delete the images programatically ?

Upvotes: 0

Views: 555

Answers (1)

Jayesh Khasatiya
Jayesh Khasatiya

Reputation: 2140

Try This:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File("folderPATH", "fileName"); //OR  File f = new File(YourCurrentPhotoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    appContext.sendBroadcast(mediaScanIntent);
} else {
    appContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/" + "FOLDER_TO_REFRESH")));
}

thats it...

Upvotes: 1

Related Questions