B bocker77 Active Member Licensed User Longtime User Jan 28, 2025 #1 Microsoft has an easy way to lock a file with a password. It looks to me like Android doesn't or I haven't seen any information that it can. Android apps that can password protect files wouldn't, I believe, be able to acces my internal app's files anyway. And it looks like some are getting bad reviews! Researching through the forum it looks as if the only way is through encryption. I don't need it encrypted, I just need to password protect it. I may have missed something in my search though. Is there a way in B4A to do what I am wanting to do or is this an Android limitation.
Microsoft has an easy way to lock a file with a password. It looks to me like Android doesn't or I haven't seen any information that it can. Android apps that can password protect files wouldn't, I believe, be able to acces my internal app's files anyway. And it looks like some are getting bad reviews! Researching through the forum it looks as if the only way is through encryption. I don't need it encrypted, I just need to password protect it. I may have missed something in my search though. Is there a way in B4A to do what I am wanting to do or is this an Android limitation.
Erel B4X founder Staff member Licensed User Longtime User Jan 29, 2025 #2 There is no such thing in Android, however files in File.DirInternal (=XUI.DefaultFolder) are only accessible by your app so they are practically protected. Upvote 0
There is no such thing in Android, however files in File.DirInternal (=XUI.DefaultFolder) are only accessible by your app so they are practically protected.
B bocker77 Active Member Licensed User Longtime User Jan 29, 2025 #3 Yes but my fingers and brain sometimes don't work well and I am afraid I will delete a game database and tick off my fellow gamers. So if I could somehow quarantee that this doesn't happen. I guess my only option is to put in a "confirm delete" message and hope that I am not stupid. Thanks for the reply. Upvote 0
Yes but my fingers and brain sometimes don't work well and I am afraid I will delete a game database and tick off my fellow gamers. So if I could somehow quarantee that this doesn't happen. I guess my only option is to put in a "confirm delete" message and hope that I am not stupid. Thanks for the reply.
B bocker77 Active Member Licensed User Longtime User Jan 30, 2025 #5 I am sorry but backup of what? The IDE'sprogram on the PC or the database on the phone? I am thinking of having a text file to hold the name of the database. Then in the delete code check if that is flagged as to being the active game's DB. Upvote 0
I am sorry but backup of what? The IDE'sprogram on the PC or the database on the phone? I am thinking of having a text file to hold the name of the database. Then in the delete code check if that is flagged as to being the active game's DB.
jahswant Well-Known Member Licensed User Longtime User Jan 30, 2025 #6 If app is uninstalled you loose everything in File.DirInternal. You can save and restore your databases as needed in your serer or as the user to save it somewhere. Upvote 0
If app is uninstalled you loose everything in File.DirInternal. You can save and restore your databases as needed in your serer or as the user to save it somewhere.
E emexes Expert Licensed User Longtime User Jan 30, 2025 #7 bocker77 said: I am sorry but backup of what? Click to expand... Of your phone. But I am confused anyway, about whether it is a third-party game or a game that you are writing, and it sounds like you've got your itchy delete finger under control now, so... no worries! Upvote 0
bocker77 said: I am sorry but backup of what? Click to expand... Of your phone. But I am confused anyway, about whether it is a third-party game or a game that you are writing, and it sounds like you've got your itchy delete finger under control now, so... no worries!
B bocker77 Active Member Licensed User Longtime User Jan 30, 2025 #8 If you a familiar with the board game "Axis and Allies 1940" the program that I wrote keeps track of the money (Industrial Production Credits) aspects of the game. This is a vital part of it. What the game offers to keep track has a lot to be desired and it can be quite time consumming. Upvote 0
If you a familiar with the board game "Axis and Allies 1940" the program that I wrote keeps track of the money (Industrial Production Credits) aspects of the game. This is a vital part of it. What the game offers to keep track has a lot to be desired and it can be quite time consumming.
B Brian Dean Well-Known Member Licensed User Longtime User Jan 30, 2025 #9 Okay - I think that I see what you are doing. You have written an app that keeps track of scores in a game on behalf of all of the players, probably bridging over several sessions. You want to make sure that the file is not accidentally deleted. If you keep the file in File.DirInternal then it will be safe, as it cannot be removed by any other app or by a file manager, but it will be lost if you delete the app itself, maybe accidentally. If you save the file anywhere else on your device then it will remain if you delete the app, but it will be removable by a file manager app, so not entirely secure. I think that you have three sensible options : 1. Keep the primary copy of the file in File.DirInternal but maintain a copy in external storage. At least then you will have to make two silly mistakes in order to lose your data. 2. Keep the primary version of the file in File.DirInternal and maintain a duplicate outside of the device. This is what I usually do - every time the file is changed I FTP a copy to cloud storage. 3. You can write an external file and make it read-only, but you will need to use JavaObject - here is some sample code (AI generated) - B4X: Dim jo As JavaObject jo.InitializeNewInstance("java.io.File", Array("/storage/emulated/0/YourFile.txt")) jo.RunMethod("setReadOnly", Null) This will prevent the file being accidentally removed, but you will have to switch it to be writeable and back to read-only every time that you update it. Last edited: Jan 31, 2025 Upvote 0
Okay - I think that I see what you are doing. You have written an app that keeps track of scores in a game on behalf of all of the players, probably bridging over several sessions. You want to make sure that the file is not accidentally deleted. If you keep the file in File.DirInternal then it will be safe, as it cannot be removed by any other app or by a file manager, but it will be lost if you delete the app itself, maybe accidentally. If you save the file anywhere else on your device then it will remain if you delete the app, but it will be removable by a file manager app, so not entirely secure. I think that you have three sensible options : 1. Keep the primary copy of the file in File.DirInternal but maintain a copy in external storage. At least then you will have to make two silly mistakes in order to lose your data. 2. Keep the primary version of the file in File.DirInternal and maintain a duplicate outside of the device. This is what I usually do - every time the file is changed I FTP a copy to cloud storage. 3. You can write an external file and make it read-only, but you will need to use JavaObject - here is some sample code (AI generated) - B4X: Dim jo As JavaObject jo.InitializeNewInstance("java.io.File", Array("/storage/emulated/0/YourFile.txt")) jo.RunMethod("setReadOnly", Null) This will prevent the file being accidentally removed, but you will have to switch it to be writeable and back to read-only every time that you update it.
B bocker77 Active Member Licensed User Longtime User Jan 31, 2025 #10 Thanks Brian for your recommendations. I will look into the Java code if I decide to go that route. Upvote 0
LucaMs Expert Licensed User Longtime User Jan 31, 2025 #11 jahswant said: If app is uninstalled you loose everything in File.DirInternal. Click to expand... No, data remains unless you write in the Manifest file: SetApplicationAttribute(android:allowBackup, "false") Upvote 0
jahswant said: If app is uninstalled you loose everything in File.DirInternal. Click to expand... No, data remains unless you write in the Manifest file: SetApplicationAttribute(android:allowBackup, "false")
B Brian Dean Well-Known Member Licensed User Longtime User Jan 31, 2025 #12 No, data remains . . . Click to expand... That is useful to know. So how would I get access to this file - what is the pathname? And will it stay there for ever? Upvote 0
No, data remains . . . Click to expand... That is useful to know. So how would I get access to this file - what is the pathname? And will it stay there for ever?
LucaMs Expert Licensed User Longtime User Jan 31, 2025 #13 Brian Dean said: what is the pathname? Click to expand... Erel said: File.DirInternal (=XUI.DefaultFolder) Click to expand... Upvote 0
Brian Dean said: what is the pathname? Click to expand... Erel said: File.DirInternal (=XUI.DefaultFolder) Click to expand...