Android: Captured Image Not Showing Up In Gallery (media Scanner Intent Not Working)
Solution 1:
It depends on how this device Gallery
implement. Popular photo apps receive Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
broadcast but some just listen to Android media database.
Alternative you can insert a image into the MediaStore
manually at the same time.
publicfinalvoidnotifyMediaStoreScanner(final File file) {
try {
MediaStore.Images.Media.insertImage(mContext.getContentResolver(),
file.getAbsolutePath(), file.getName(), null);
mContext.sendBroadcast(newIntent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Addition, make sure your photo not in a private
folder, like internal storage or write with Context.MODE_PRIVATE
. Otherwise other apps will not have the permission to access this file.
Solution 2:
In Android if you capture or add images in SD card or Etc. from the application.
It will not shown sometimes in gallery for some time.
If you capture and just wait for some time till syncing process done you will able to see.
You might not see on the spot.
Solution 3:
Try below Code
privatevoidscanGallery(final Context cntx, String path) {
try {
MediaScannerConnection.scanFile(cntx, newString[] { path },null, newMediaScannerConnection.OnScanCompletedListener() {
publicvoidonScanCompleted(String path, Uri uri) {
//unimplemeted method
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
here imagePath is the captured image full path
Solution 4:
In my case, it was silently failing because I had both permissions in the manifest:
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You only need WRITE_EXTERNAL_STORAGE
. The rest of the code, taken from the docs, didn't need any modifications, but check the other answers in case the cause is different.
Post a Comment for "Android: Captured Image Not Showing Up In Gallery (media Scanner Intent Not Working)"