-1
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();

I am trying to delete a photo from MediaStore. On this piece of code, it gives me this error:

'delete(android.net.Uri, java.lang.String, java.lang.String[])' in 'android.content.ContentResolver' cannot be applied to '(java.net.URI, null, null)'

However, the official documentation about it says that second and third values are allowed to be null. What is the problem here?

Here is a photo of the official documentation: https://i.stack.imgur.com/WY6AD.jpg

Here is the official documentation itself.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Shazniq
  • 423
  • 4
  • 16

1 Answers1

1

The answer is; The problem wasn't with nulls. The problem was with the first argument. The method takes Uri, I gave the method URI. They're different apparently. I used ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getInt(0)); as uri instead. It's working good.

Shazniq
  • 423
  • 4
  • 16