File name after MediaStore.Images.Media.insertImage

痴心易碎 提交于 2019-12-24 10:45:13

问题


I am using MediaStore.Images.Media.insertImage(ContentResolver cr, String imagePath, String name, String description) function to insert a newly created image into gallery. System is naming the file by default, but it's diferent than names of pictures taken by orginal app (Time stamp). Is there easy way to set it up?


回答1:


I use something like this

Uri u;
File fi = new File("/sdcard/tmp");
try {
    u = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), fi.getAbsolutePath(), null, null));
    imageSaveName1 = u.toString();

}

imageSaveName1 looks something like "content://media/external/images/media/159"




回答2:


According to the reference, insertImage returns the URL:

Returns
      The URL to the newly created image

Did it not work?




回答3:


InsertImage, or just inserting ContentValues and writing to the uri, results in a file name of the date's long value.

For example I present my situation. Inserting content values where the mime type is specified as image/gif, and then writing to the resulting uri, results in a file xxxxxxxxx.jpg. The specified mime type is ignored entirely. The resulting gif image in the MediaStore does not animate and is essentially broken being displayed as a standard jpeg.

At this point I see no way to insert content values and specify a specific filename after writing to the resulting uri via a stream. Specifying the mime type in MediaScannerConnection does not help either.



来源:https://stackoverflow.com/questions/2657827/file-name-after-mediastore-images-media-insertimage

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