android - adding pic to the gallery app

33 views Asked by At

I have an app that takes pictures and they are uploaded full-size. I want them to be shown in the gallery app. I'm using:

private void galleryAddPic() {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(imagepath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}

It works in 5.0 but not in 4.3. The imagepath is an absolute path

1

There are 1 answers

0
sttimchenko On BEST ANSWER

Try smthing like this...

private void galleryAddPhoto() {
    sendBroadcast(
            new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    Uri.parse("file://" + mCurrentFilteredPhotoPath))
    );
}

This method will add your file to gallery using it's position, where mCurrentFilteredPhotoPath is a String object