Android saves pictures to albums and sees them in time

Source: Internet
Author: User

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

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.