Android sd card cannot immediately display the file to be written after the file is written. Solution: Android sd

Source: Internet
Author: User

Android sd card cannot immediately display the file to be written after the file is written. Solution: Android sd

Every time a file is written to the SD card through an output stream, the file is connected to the computer, and a mobile disk is simulated using MTP. Opening the disk does not have such a file, and you can view it through adb, the cause is that the MTP database is not updated after each write, because the price required to update the MTP database is large, so it is only restarted, mounting and sending Intent messages manually. Therefore, you need to manually send Intent broadcasts after saving the files to start updating the MTP database.

/*** Start to scan the files in mtp. After saving the files to the SD card, they cannot be displayed. Therefore, the scan mechanism is triggered to connect the mobile phone to the computer, you can read the file * @ param fName, the complete path name of the file */public void fileScan (String fName) {Uri data = Uri. parse ("file: //" + fName); sendBroadcast (new Intent (Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, data ));


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.