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
Indexed value of File#lastModified() extracted from this media item. This constant represents a column name that can be used with a ContentProvider through a ContentValues or Cursor object. The values stored in this column are Cursor#FIELD_TYPE_INTEGER , and are read-only and cannot be mutated.
doc
you can't update this,just use File.setLastModified