How to get all the audio file information in the library and update the Media Library when the file is deleted

Source: Internet
Author: User

Before the 4.4 release, we can force the Media Library to be refreshed by sending a broadcast

Intentfilter Intentfilter =New Intentfilter (      intent.action_media_scanner_started);  Intentfilter.addaction (intent.action_media_scanner_finished);   Intentfilter.adddatascheme ( "file");   Sendbroadcast (new Intent (intent.action_media_mounted,     Uri.parse ( "file://"       + environment.getexternalstoragedirectory ()                    

After you send the broadcast, you also need to register a broadcast recipient to accept and process the scan start and end events

PrivateClassScanreceiverExtendsBroadcastreceiver {  Publicvoid OnReceive (Context context, Intent Intent) {     //when the system starts scanning the SD card, for the user experience, You can add a wait box    if (intent.action _media_scanner_started.equals (Action)) {  }   //when the system scan is complete, stop the display of the Wait box, and requery Contentprovider   if ( Intent.ACTION_MEDIA_SCANNER_FINISHED.equals (ACTION)) {  } }}     /span>                

In this way, we can force the Media Library to be updated.

However, after 4.4, Android has increased permissions on some operations, and if you use this method on a 4.4 system, the following error will occur

From pid=22360, uid=10163 

This is because after 4.4, this broadcast can only be issued by the system application, so we can't use this method, we could use the following code to achieve the same function:

Mediascannerconnection.scanfile (new string[] {environment      null);  

Using Mediascannerconnection's Scanfile method, we can force scan the file path we need to update, and then the media database will be updated synchronously, so that there will be no file deletion, in the Media Library can search for the situation, can also solve the new song that the friend raised the information acquisition problem.

Original:

Http://www.tuicool.com/articles/vyYZny

How to get all the audio file information in the library and update the Media Library when the file is deleted

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.