androidandroid-mediascanner

Force scan files after taking photo


on api level 4 (android 1.6), after taking photo using:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(Environment.getExternalStorageDirectory(), "NewPic.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, TAKE_PICTURE);

I'd like to look through all my photos thumbnails, but there is no my last photo thumbnail. It works perfectly on android 2.1.

If I connect device via USB to PC and then disconnect file will appear, after finished scanning. So how should I start that indexing?

I tried

mScanner = new MediaScannerConnection(getApplicationContext(), this);
mScanner.connect();
mScanner.scanFile(imageUri.getEncodedPath(), "*/*");

And end with this:

02-24 17:13:54.678: DEBUG/MediaScannerService(1320): IMediaScannerService.scanFile: /sdcard/NewPic2222.jpg mimeType: */*
02-24 17:13:54.688: VERBOSE/MediaProvider(1320): /sdcard volume ID: 1149784819
02-24 17:13:54.688: VERBOSE/MediaProvider(1320): key exists

EDITED LATER

I've got sth like this in other activity

mCursorThumbnails = MediaStore.Images.Thumbnails.queryMiniThumbnails(mContentResolver, MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, MediaStore.Images.Thumbnails.MINI_KIND, projection);
mCursorImages = MediaStore.Images.Media.query(mContentResolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection);

When I check count of first value I've got 13 elements, and on the second I've got 14. So the image has been added to mediascanner, but OS hasn't generated thumbnail for it. So how should I ask OS to create one?


Solution

  • after taking picture try calling insert() function of ContentResolver passing the information about the picture.

    public final Uri insert (Uri url, ContentValues values)
    

    It will actually add the picture to the database and create picture's thumbnail image for you. It will also be added to the thumbnail database. Hope this helps!