【问题标题】:getContentResolver().delete(uri,null,null) gives an error even though the official documentation says it shouldn't [duplicate]getContentResolver().delete(uri,null,null) 给出错误,即使官方文档说它不应该[重复]
【发布时间】:2021-03-02 14:39:30
【问题描述】:
System.out.println(DatabaseUtils.dumpCursorToString(cursor));
URI uri = new File(path).toURI();
getApplicationContext().getContentResolver().delete(uri, null, null);//This is the one giving the error
new File(path).delete();
refreshCursor();
setTheImage();

我正在尝试从 MediaStore 中删除一张照片。在这段代码上,它给了我这个错误:

'android.content.ContentResolver' 中的'delete(android.net.Uri, java.lang.String, java.lang.String[])' 不能应用于'(java.net.URI, null, null )'

但是,关于它的官方文档说第二个和第三个值允许为空。 这里有什么问题?

这是官方文档的照片:https://imgur.com/a/OenSEL7

Here 是官方文档本身。

【问题讨论】:

  • @RyanM 问题已经得到解答,谢谢

标签: java android mediastore


【解决方案1】:

答案是; 问题不在于空值。问题在于第一个论点。方法取Uri,我给方法URI。他们显然是不同的。 我改用ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getInt(0)); 作为uri。效果很好。

【讨论】:

  • 不,这没有帮助。您应该使用从媒体商店获得的 uri。不是你自己建立的。
  • 或者按照这里的做法:stackoverflow.com/questions/66438012/…
  • 你是对的。我会编辑它。
猜你喜欢
  • 2021-12-05
  • 2012-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多