Intent. action_media_scanner_scan_file: scan a specified file

Source: Internet
Author: User

1. Start the mediascanner service and scan media files:
The program starts the mediascanner service to scan the specified file or directory by sending the following intent:

Intent. action_media_scanner_scan_file: scan a specified file

12345
public void scanFileAsync(Context ctx, String filePath) {              Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);              scanIntent.setData(Uri.fromFile(new File(filePath)));              ctx.sendBroadcast(scanIntent);       }

"Android. Intent. Action. media_scanner_scan_dir": scans the specified directory.

123456
public static final String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR";       public void scanDirAsync(Context ctx, String dir) {              Intent scanIntent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR);              scanIntent.setData(Uri.fromFile(new File(dir)));              ctx.sendBroadcast(scanIntent);       }

In this scan mode, the current program process is not blocked because the scan is performed in the mediascanner service. This scan method is applicable when scanning a large number of media files with low real-time requirements.

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.