Rhidoy Rhidoy - 1 year ago 79
Android Question

How Sync android galley when capture a new image which save to custom folder

i implements an app which capture image and save them to my custom folder. everything is OK but the problem is, my gallery don't get sync when i capture image. it means gallery don't show new capture image. for that i need to reboot my phone.

Here is my image capture code....

if (requestCode == 0 && resultCode == RESULT_OK) {
String[] projection = {MediaStore.Images.ImageColumns.SIZE,
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
final String selection = MediaStore.Images.Media.DATE_TAKEN + " > " + time;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
CursorLoader loader = new CursorLoader(this, u,
projection, selection, null, imageOrderBy);
Cursor cursor = loader.loadInBackground();
if (null != cursor && cursor.moveToFirst()) {
ContentResolver cr = this.getContentResolver();
BaseColumns._ID + "=" + cursor.getString(3), null);
//showing image in image view
cameraPicture = output.getPath();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(cameraPicture, options);

so how can i sync my android galley when i capture the image??? so that i can view this image immediately from galley.

Answer Source

You need notify system after saving file

 private void scanFile(String path) {

            new String[] { path }, null,
            new MediaScannerConnection.OnScanCompletedListener() {

                public void onScanCompleted(String path, Uri uri) {
                    Log.i("TAG", "Finished scanning " + path);