我尝试使用contentResolver删除文件,但仅从数据库而不是实际文件中删除条目。因此,我尝试先删除条目,然后再删除文件:
int rows = context.getContentResolver().delete(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
MediaStore.Audio.Media._ID + "=" + idSong, null);
// Remove file from card
if (rows != 0) {
Uri uri = ContentUris.withAppendedId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, idSong);
File f = new File(uri.getPath());
if(!f.delete())
Log.d("fail-2", "fail-2");
}
else
Log.d("fail-1", "fail-1");
Run Code Online (Sandbox Code Playgroud)
...,输出为“ fail-2”。为什么?
为什么ContentResolver不删除真实文件?这正常吗?