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
Use this code:
public static void scanFile(Context context, String path, String mimeType ) {
Client client = new Client(path, mimeType);
MediaScannerConnection connection =
new MediaScannerConnection(context, client);
client.connection = connection;
connection.connect();
}
private static final class Client implements MediaScannerConnectionClient {
private final String path;
private final String mimeType;
MediaScannerConnection connection;
public Client(String path, String mimeType) {
this.path = path;
this.mimeType = mimeType;
}
@Override
public void onMediaScannerConnected() {
connection.scanFile(path, mimeType);
}
@Override
public void onScanCompleted(String path, Uri uri) {
connection.disconnect();
}
}
Then just call scanFile(imageUri.getPath(), null)
.
Don't use encoded path and don't use "*/*"
as a MIME type because null
value makes scanner to determine MIME type automatically.
Whenever you add a file, let MediaStore Content Provider knows about it using the sendBroadcast method
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(mediaFileAdded)));
For deletion, use:
getContentResolver().delete(uriOfMediaFileDeteled, null, null)
Main advantage: work with any mime type supported by MediaStore
In your case, do this in onActivityResultMethod (i.e.) after the photo has been successfuly taken
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!
Use
MediaStore.Images.Thumbnails.getThumbnail(ContentResolver cr, long origId, int kind, BitmapFactory.Options options)
to force the creation of the thumbnail for an image.