LucaMs Expert Licensed User Longtime User Aug 17, 2014 #1 I guess the answer will be simpy: "no". As a matter of permissions: I could set readonly, for example, a file in the Root dir that is not mine. I ask this because I want to solve this other problem. The problem of the deleting in the case of a reinstallation that someone has highlighted.
I guess the answer will be simpy: "no". As a matter of permissions: I could set readonly, for example, a file in the Root dir that is not mine. I ask this because I want to solve this other problem. The problem of the deleting in the case of a reinstallation that someone has highlighted.
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #2 I tried this code: Code: Copy Sub SetReadOnly(Dir As String, FileName As String) 'ignore Dim r As Reflector r.Target = r.CreateObject2("java.io.File", Array As String(Dir, FileName), _ Array As String("java.lang.String", "java.lang.String")) r.RunMethod("setReadOnly") End Sub but it does not work. There is also this method: boolean setWritable(boolean writable, boolean ownerOnly) but >= API 9. The description: Manipulates the write permissions for the abstract path designated by this file. What means: "abstract path designated..."? Last edited: Aug 17, 2014 Upvote 0
I tried this code: Code: Copy Sub SetReadOnly(Dir As String, FileName As String) 'ignore Dim r As Reflector r.Target = r.CreateObject2("java.io.File", Array As String(Dir, FileName), _ Array As String("java.lang.String", "java.lang.String")) r.RunMethod("setReadOnly") End Sub but it does not work. There is also this method: boolean setWritable(boolean writable, boolean ownerOnly) but >= API 9. The description: Manipulates the write permissions for the abstract path designated by this file. What means: "abstract path designated..."?
DonManfred Expert Licensed User Longtime User Aug 17, 2014 #3 What OS is the Device running? Which version... public boolean setWritable (boolean writable, boolean ownerOnly) Added in API level 9 Manipulates the write permissions for the abstract path designated by this file. Parameters writable To allow write permission if true, otherwise disallow ownerOnly To manipulate write permission only for owner if true, otherwise for everyone. The manipulation will apply to everyone regardless of this value if the underlying system does not distinguish owner and other users. Returns true if and only if the operation succeeded. If the user does not have permission to change the access permissions of this abstract pathname the operation will fail. Starting on Android 4.idontknow the rights are limited to apps so i suppose you get an false as result when trying to use setWriteable on such devices (limited access-rights) Upvote 0
What OS is the Device running? Which version... public boolean setWritable (boolean writable, boolean ownerOnly) Added in API level 9 Manipulates the write permissions for the abstract path designated by this file. Parameters writable To allow write permission if true, otherwise disallow ownerOnly To manipulate write permission only for owner if true, otherwise for everyone. The manipulation will apply to everyone regardless of this value if the underlying system does not distinguish owner and other users. Returns true if and only if the operation succeeded. If the user does not have permission to change the access permissions of this abstract pathname the operation will fail. Starting on Android 4.idontknow the rights are limited to apps so i suppose you get an false as result when trying to use setWriteable on such devices (limited access-rights)
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #4 I tried setReadOnly, which requires API 1 (I wrote setWritable just for an alternative method). Also, I should have the permission, given that I have created the file. I have tried both DirRootExternal and DirDefaultExternal. But I found this answer (web) about setWritable: The sdcard uses a FAT-type filesystem which does not support file ownership. It is possible at implementation level for FAT to support a read-only bit, but that would be of limited value since anything else with sd card write permission would be free to change the bit. Given the limited value, it's an open question if it's even possible to set that on android. Last edited: Aug 17, 2014 Upvote 0
I tried setReadOnly, which requires API 1 (I wrote setWritable just for an alternative method). Also, I should have the permission, given that I have created the file. I have tried both DirRootExternal and DirDefaultExternal. But I found this answer (web) about setWritable: The sdcard uses a FAT-type filesystem which does not support file ownership. It is possible at implementation level for FAT to support a read-only bit, but that would be of limited value since anything else with sd card write permission would be free to change the bit. Given the limited value, it's an open question if it's even possible to set that on android.
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #5 !!! ??? http://www.mkyong.com/java/how-to-make-a-file-read-only-in-java/ Upvote 0
DonManfred Expert Licensed User Longtime User Aug 17, 2014 #6 LucaMs said: !!! ??? http://www.mkyong.com/java/how-to-make-a-file-read-only-in-java/ Click to expand... >Posted on August 23, 2010 >File file = new File("c:/file.txt");> Seems that this post is facing a windows-java-code-snippet... And this post is four years old. When did android 4 came out... End of 2011 i supose.... The restrictions to apps in android came with android 4.something... I believe it was 4.4 but not sure. That´s why i asking which android version the device is running which you tried Upvote 0
LucaMs said: !!! ??? http://www.mkyong.com/java/how-to-make-a-file-read-only-in-java/ Click to expand... >Posted on August 23, 2010 >File file = new File("c:/file.txt");> Seems that this post is facing a windows-java-code-snippet... And this post is four years old. When did android 4 came out... End of 2011 i supose.... The restrictions to apps in android came with android 4.something... I believe it was 4.4 but not sure. That´s why i asking which android version the device is running which you tried
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #7 4.04 Now I try on an emulator with an older S.O. [2.3.3 API 10 - same] [2.2 API 8 - same] Last edited: Aug 17, 2014 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2014 #8 Check the return value of r.RunMethod("setReadOnly") to see whether the operation succeeded or not. Upvote 0
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #9 Well, I created a file, then I called the routine to make the file readonly and then I tried to delete the file (in a Try-Catch). Unfortunately it was deleted in each test. Attachments lm setReadOnly.zip lm setReadOnly.zip 11.5 KB · Views: 587 Upvote 0
Well, I created a file, then I called the routine to make the file readonly and then I tried to delete the file (in a Try-Catch). Unfortunately it was deleted in each test.
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2014 #10 Check the value returned by the call. Android file system doesn't support this attribute if I remember correctly. Upvote 0
Check the value returned by the call. Android file system doesn't support this attribute if I remember correctly.
LucaMs Expert Licensed User Longtime User Aug 17, 2014 #11 It is False: But then, why: http://developer.android.com/reference/java/io/File.html#setReadOnly() ? Mah! Upvote 0
It is False: But then, why: http://developer.android.com/reference/java/io/File.html#setReadOnly() ? Mah!
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2014 #12 See the explanation here: http://stackoverflow.com/questions/...an-readonly-file-on-the-android-sd-card-fails Upvote 0
See the explanation here: http://stackoverflow.com/questions/...an-readonly-file-on-the-android-sd-card-fails
LucaMs Expert Licensed User Longtime User Aug 18, 2014 #13 Erel said: See the explanation here: http://stackoverflow.com/questions/...an-readonly-file-on-the-android-sd-card-fails Click to expand... #4 Upvote 0
Erel said: See the explanation here: http://stackoverflow.com/questions/...an-readonly-file-on-the-android-sd-card-fails Click to expand... #4