Android: Refreshing the Gallery after saving new images
Code provided by Petrus in another answer works for me on Kitkat (4.4):
MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
/*
* (non-Javadoc)
* @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
*/
public void onScanCompleted(String path, Uri uri)
{
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
How to refresh Gallery after deleting image from SDCard
You should delete it from mediaStore
public static void deleteFileFromMediaStore(final ContentResolver contentResolver, final File file) {
String canonicalPath;
try {
canonicalPath = file.getCanonicalPath();
} catch (IOException e) {
canonicalPath = file.getAbsolutePath();
}
final Uri uri = MediaStore.Files.getContentUri("external");
final int result = contentResolver.delete(uri,
MediaStore.Files.FileColumns.DATA + "=?", new String[] {canonicalPath});
if (result == 0) {
final String absolutePath = file.getAbsolutePath();
if (!absolutePath.equals(canonicalPath)) {
contentResolver.delete(uri,
MediaStore.Files.FileColumns.DATA + "=?", new String[]{absolutePath});
}
}
}
How to refresh a gallery after capturing a screenshot?
Try this method. It shouldn't have the permission issues.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));
how to update gallery after moving photo programmatically?
to remove from gallery
try {
getContentResolver().delete();
} catch (Exception e) {
e.printStackTrace();
}
Related Topics
How to Detect If Changes Were Made in The Preferences
How to Add a View Programmatically to Relativelayout
Session 'App': Error Installing APK
Starting Activity Through Notification: Avoiding Duplicate Activities
Android Studio 3.1 Edittext Stackoverflowerror
When Does Application's Oncreate() Method Get Called
How to Change Android:Windowsoftinputmode Value from Java Class
Android Gcm Basic Implementation
Package Signatures Do Not Match The Previously Installed Version
How to Restrict My Edittext Input to Numerical (Possibly Decimal and Signed) Input
How to Put My Libraries in Front of Android.Jar by Editing Build.Gradle in Android-Studio
Showing The Current Selection in a Listview
Adb Doesn't Recognize My Galaxy Nexus - Win7
Android: How to Get a Modal Dialog or Similar Modal Behavior
Play Store Having New Version of The App, But Not Showing Update
How to Get Total Ram Size of a Device
Android Edittext Listener for Cursor Position Change
Does Android Studio Have a Hierarchy Viewer or Layout Inspector