Android: Save Bitmap to Gallery ==> Time created wrong

北城以北 提交于 2019-12-05 07:14:39

You need to define DATE_TAKEN when inserting the image. This can be done by altering the way you add images to the gallery, and doing something like the following:

public static Uri addImageToGallery(Context context, String filepath, String title, String description) {    
    ContentValues values = new ContentValues();
    values.put(Media.TITLE, title);
    values.put(Media.DESCRIPTION, description); 
    values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
    values.put(Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.MediaColumns.DATA, filepath);

    return context.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
}

If you need any other pointers, I would take a look at MediaStore.Images.Media.insertImage

Have you imported correctly the class java.util.Date? Maybe the auto-import took the one from sql, common mistake.

clwhisk

For those who come after me: the system will generate a stamp for the time you added the image with insertImage(...) but only after a restart or other refresh of the gallery. Follow the approach of Get filename and path from URI from mediastore combined with https://stackoverflow.com/a/5814533/2563422 to notify the gallery immediately each bitmap you store.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!