Android Question Set/Preserve File Timestamps

andrewj

Active Member
Licensed User
Longtime User
Hi,
I'm implementing some file operations using the file.copy() method. Is there any way to either preserve the timestamp of the original file, or re-set the timestamp on the copy to the same value as the source file after copying?

Thanks
Andrew
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this sub:
B4X:
Sub SetLastModified(Dir As String, FileName As String, Time As Long) As Boolean
   Dim jo As JavaObject
   jo.InitializeNewInstance("java.io.File", Array As Object(Dir, FileName))
   Return jo.RunMethod("setLastModified", Array As Object(Time))
End Sub
Check the value return. On many devices it will return False due to this Android issue:
https://code.google.com/p/android/issues/detail?id=18624
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Thanks Erel,
The code works, but unfortunately I'm on a Note 10.1 and have the same problem as many other users.
Hopefully this will resolve with later versions of Android.
Andrew
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…