Android Question How to set file permissions before copy?

ihatton

Member
Licensed User
Longtime User
Hi,

I am using file.copy to copy files from the SD card of a device to another location. I also need to be able to set the file permissions using setWritable, SetReadable and setExecutable (from http://developer.android.com/reference/java/io/File.html) . I didn't see any reference to these methods in the online B4A docs/forums so the question is whether they are supported and if not, is there any alternative method to set file permissions?

Best Regards,
Ian Hatton
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use JavaObject for that:
B4X:
Dim jo As JavaObject
   jo.InitializeNewInstance("java.io.File", Array As Object(File.Combine(File.DirRootExternal, "1.jpg")))
   Log(jo.RunMethod("setReadOnly", Null))

Check the returned value. It will probably be false (operation failed) because most external storages do not support these permissions.
 
Upvote 0
Top