I'm struggling to update metadata in the mediastore with a DocumentFile/TreeUri. This is how I tried to do it:
boolean canWrite = documentFile.canWrite(); //returns true
Uri mediaUri = MediaStore.getMediaUri(context, documentFile.getUri());
ContentValuesvalues = new ContentValues();
values.put(MediaStore.MediaColumns.DATE_MODIFIED, newLastModified);
boolean success = context.getContentResolver().update(mediaUri, values,null, null) > 0;
It fails and the logcat reads:
W/MediaProvider: Ignoring mutation of date_modified
What am I doing wrong? The DocumentFile is writable, it is received via Intent.ACTION_OPEN_DOCUMENT_TREE and takePersistableUriPermission was called on the folder. I also tried updating the entry with IS_PENDING before and removed after:
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.IS_PENDING, 1);
boolean success = context.getContentResolver().update(mediaUri, values,
null, null) > 0; //returns false
returns for whatever reason also false, but I see that the file is prefixed with .pendingxxxx, so it seemed to work
ContentValuesvalues = new ContentValues();
values.put(MediaStore.MediaColumns.DATE_MODIFIED, newLastModified);
values.put(MediaStore.MediaColumns.IS_PENDING, 0);
boolean success = context.getContentResolver().update(mediaUri, values,null, null) > 0; //returns false