Android will save the picture to the SD card, the photo album will not appear in time, because the index is not updated in time, generally need to boot several times. Of course we can manually update its index.
1, first save the file to the SD card.
String filePath = "xxx"; Full path
Saveimgtosdcard (FilePath);
2, add Android internal Media index.
public boolean saveimgtogallery (String filePath) {
Boolean sdcardexist = Environment.getexternalstoragestate (). Equals (
Android.os.Environment.MEDIA_MOUNTED); Determine if the SD card exists
if (!sdcardexist)
return false;
try {
Contentvalues values = new Contentvalues ();
Values.put ("Datetaken", New Date (). toString ());
Values.put ("Mime_type", "image/jpg");
Values.put ("_data", FilePath);
Application app = Doctorapplication.getinstance ();
Contentresolver CR = App.getcontentresolver ();
Cr.insert (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (Exception e) {
E.printstacktrace ();
}
return true;
}
3, refresh the top level of the FilePath directory
Mediascannerconnection.scanfile (mylanjingcode.this,new string[] {environment. Getexternalstoragepublicdirectory (environment.directory_dcim). GetPath ()+ "/" + filepath.getparentfile () . GetAbsolutePath ()}, NULL,null);
This will make it possible to see the added images in the album in Time.
Android saves pictures to albums and sees them in time