Android Question Locking a File in File.DirInternal

bocker77

Active Member
Licensed User
Longtime User
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.
 

bocker77

Active Member
Licensed User
Longtime User
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

bocker77

Active Member
Licensed User
Longtime User
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

jahswant

Well-Known Member
Licensed User
Longtime User
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

bocker77

Active Member
Licensed User
Longtime User
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

Brian Dean

Well-Known Member
Licensed User
Longtime User
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:
Upvote 0

Similar Threads

Top