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)