【发布时间】:2020-10-02 22:50:42
【问题描述】:
我尝试使用 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");
...输出为“fail-2”。为什么?
为什么 ContentResolver 不删除真实文件?这正常吗?
【问题讨论】:
标签: android android-contentresolver mediastore