How to update the Android media database

前端 未结 4 1246
离开以前
离开以前 2020-12-03 02:02

My application shows the list of songs in sdcard, and there is an option to delete the song from SD card.

Even when the song is deleted the song still comes in my ap

4条回答
  •  無奈伤痛
    2020-12-03 02:53

    Android has a cache of sorts that keeps track of media files.

    Try this:

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    It makes the MediaScanner service run again, which should remove the deleted song from the device's cache.

    You also need to add this permission to your AndroidManifest.xml:

    
      
       
    
    

提交回复
热议问题