jes*_*res 5 android mediastore android-contentresolver
我尝试使用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不删除真实文件?这正常吗?
这是工作:
// Remove entry from database
int rows = context.getContentResolver().delete(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
MediaStore.Audio.Media._ID + "=" + idSong, null);
// Remove file from card
if (rows != 0) {
try {
File f = new File(path);
if (f.delete())
return true;
} catch (Exception e) {
Log.d("MusicDB", "file: '" + path
+ "' couldn't be deleted", e);
return false;
}
}
return false;
Run Code Online (Sandbox Code Playgroud)
但为什么 contentResolver 不删除该文件?
| 归档时间: |
|
| 查看次数: |
2587 次 |
| 最近记录: |