Android's Media Scanner: How do I remove files?

前端 未结 5 693
轮回少年
轮回少年 2020-12-08 17:42

I\'m writing an app that removes files that may or may not be listed in any one of the types of media libraries such as music or pictures. While I can use the MediaSca

5条回答
  •  情书的邮戳
    2020-12-08 17:45

    Easy as pie: whenever you add a file, let MediaStore ContentProvider knows about it using

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(fileToAddInMediaStore)));
    

    For deletion: just use

    getContentResolver().delete(Uri.fromFile(fileToDeleteFromMediaStore), null, null)
    

提交回复
热议问题