I have an issue refreshing the gallery on the android device. Android device being used to debug with is a Galaxy Note 3 with NO sd card.
After deleting a file, a refresh has to be done on the entire gallery otherwise the image is still visible in the gallery of the phone even though it has been deleted (because there isn't a better way to do this for the deletion of a file to my knowledge)
But when I do the refresh the app force closes. I would guess that it has something to do with the phone not having a SD card to mount/unmount.
Is there a way to refresh the gallery besides this piece of code? Or do you know why the application would force close after the delete?
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
I've also tried playing with that code as to change it to something like this, but still the error persists.
String selectedFile = getRealPathFromURI(selectedURI);
me.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(selectedFile)));
private String getRealPathFromURI(Uri contentURI) {
Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
}
Also just for a last resort I tried this. The app didn't crash, but didn't scan the file / or fix the problem either.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
EDIT: I have added the permissions in the Manifest only for
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Found how to fix this.
You have to execute this on the main thread. There might be a way around this and if some one would add to this then it would be great.
So Fix : This has to be executed in your main activity for some reason.