I want to copy or move files from the internal storage to the sd card. I do this via the Storage Access Framework (SAF) and the DocumentFile
class...
Copying is stream based and the DocumentFile
does not have a function like the File
class to set the last modified date.
I know, that I move/copy files to the sd card, so I know that I create a local file. With this information, is it somehow possible to update the last modified date of the underlying file of the DocumentFile
?
It seems like you can't move/copy files from your internel storage to the sd card without losing the last modified date...
Reading - Working
public long lastModified(DocumentFile file, Context context)
{
long lastModified = 0;
final Cursor cursor = context.getContentResolver().query(file.getUri(), null, null, null, null);
try
{
if (cursor.moveToFirst())
lastModified = cursor.getLong(cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED));
}
finally
{
cursor.close();
}
return lastModified;
}
WRITING - NOT WORKING
public boolean setLastModified(DocumentFile file, Context context, long time)
{
ContentValues updateValues = new ContentValues();
updateValues.put(DocumentsContract.Document.COLUMN_LAST_MODIFIED, time);
int updated = context.getContentResolver().update(file.getUri(), updateValues, null, null);
return updated == 1;
}
This fails with a java.lang.UnsupportedOperationException: Update not supported
exception...