Android inserts a picture into the system album with two identical pictures (only the image size is inconsistent)

Source: Internet
Author: User
Tags dcim folder

Insert a picture into a system album when this method is called, two identical pictures appear in the album

MediaStore.Images.Media.insertImage

A picture is the original picture is a thumbnail image. The representation is as follows: The thumbnail image inserted in the android4.4.4 system and the DCIM folder in the SDcard root directory This, Android5.0 above the model inserted thumbnails in the SDcard root directory under the Pictures folder, the original image is stored in the DCIM folder.

The cause of this problem after viewing the code, you know that the system automatically generates a thumbnail image and saves the corresponding file directory, as follows.

The solution is to comment out the code in the Red box.

The following code is compiled:

Publicvoidinsertimage (String fileName) {//Toast.maketext (This, "Insert Picture", Toast.length_long). Show ();        Try{Insertimagew (Getcontentresolver (), FileName,NewFile (fileName). GetName (),NewFile (fileName). GetName ()); Intent Intent=NewIntent (Intent.action_media_scanner_scan_file); Uri URI= Uri.fromfile (NewFile (fileName));            Intent.setdata (URI);            Sendbroadcast (Intent); Mediascannerconnection.scanfile ( This,NewString[] {fileName},NewString[] {"Image/jpeg" },                    Newmediascannerconnection.mediascannerconnectionclient () {@Override publi Cvoidonmediascannerconnected () {} @Override Public /c4>voidonscancompleted (String path, Uri uri) {photogalleryfragment.addcapturefile (path);        }                    }); } Catch(FileNotFoundException e) {e.printstacktrace (); }    }
Public String Insertimagew (contentresolver cr, String ImagePath, string name, string description) throws Fi lenotfoundexception {//Check if file exists with a fileinputstreamFileInputStream stream =NewFileInputStream (ImagePath); Try{Bitmap BM=Bitmapfactory.decodefile (ImagePath); String ret=Insertimaget (CR, BM, name, description);            Bm.recycle (); returnret; } finally {            Try{stream.close (); } Catch(IOException e) {}}} Public String insertimaget (contentresolver cr, Bitmap Source, string title, string description) {Contentvalues VA Lues=Newcontentvalues ();        Values.put (Images.Media.TITLE, TITLE);        Values.put (Images.Media.DESCRIPTION, DESCRIPTION); Values.put (Images.Media.MIME_TYPE,"Image/jpeg"); Uri URL=NULL; String StringUrl=NULL;/*value to be returned*/        Try{String Content_authority_slash= "content://" + "media" + "/"; Uri URI= Uri.parse (Content_authority_slash + "external" + "/images/media"); URL=Cr.insert (URI, values); } Catch(Exception e) {LOG.E ("Heheh", "Failed to insert Image", E); if(URL! =NULL) {cr.Delete(URL,NULL,NULL); URL=NULL; }        }        if(URL! =NULL) {StringUrl=url.tostring (); }        returnStringUrl; }

Android inserts a picture into the system album with two identical pictures (only the image size is inconsistent)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.