The problem of saving images to SD card in Android is not displayed in time

Source: Internet
Author: User

When you save the picture after opening gallery, some will automatically refresh you, some do not, so that the picture saved to the SD card, not in time to see in gallery, encountered this situation is best to refresh themselves.

Full SD card scanning via intent.action_media_mounted:

The code is as follows Copy Code
public void Sdscan () {
Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://")
+ environment.getexternalstoragedirectory ()));
}

To scan a file by Intent.action_media_scanner_scan_file:

The code is as follows Copy Code

public void FileScan (String filePath) {
Uri data = Uri.parse ("file://" +filepath);
Sendbroadcast (New Intent (Intent.action_media_scanner_scan_file, data));
}

Note: filepath is the address of the picture in the SD card, when the picture is saved, call the above method; Sendbroadcast is a method of the class context.

Related Article

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.