How to update the Android media database

前端 未结 4 1249
离开以前
离开以前 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 03:00

    Gallery refresh including Android KITKAT

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            File f = new File("file://"+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
            Uri contentUri = Uri.fromFile(f);
            mediaScanIntent.setData(contentUri);
            this.sendBroadcast(mediaScanIntent);
    }
    else
    {
           sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    } 
    

提交回复
热议问题