How to save text File privately which should be stored in device storage

I don’t know what to do to save file privately or encryptedly, I mean the file which should be only accessible to my app but available in storage also, Is this possible? And if I want to edit that file with the app, like change the whole text to something else, is this possible? And will this be visible to my storage of phone also?

I tried for public which was giving me error 2103 and checked different topics on kodular but I don’t find the one for me, then decided to post here to learn for private.

You can store a file 1) inside the app (file scope App) or 2) in shared storage (file scope Shared or Legacy)

Each time the file technically is stored in the internal (emulated) sdcard. For 1) it is not accessible for other apps.

For more information see Some basics on Android storage system and the documentation about file scopes File - Kodular Docs, probably better to read here Storage

Taifun

If we delete app and then download again then it should take data from that file only. That’s what I want

And I tried for legacy, it was giving error 2103

If I use inside the app then it will be deleted on deletion of app, right?

1 Like


also set FileScope to App
and remove the slash… use only the filename
Taifun

But i want to store it through legacy. So my data would be stored as file and if app deleted then file will be safe. How can I do that? @Taifun

safe means will not get deleted?
yes, just use Legacy and the file will be stored in shared storage accessible for all apps
next time if you reinstall the app and want to read the file again, you will need SAF, see also Some basics on Android storage system

Taifun

I selected shared on it and it was saving file with the text in shared but when tried to retrieve it using the file name, it was not getting retrieve. Will legacy be visible or editable by other apps also?

Yep safe means not deleted
@Taifun

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select “Download Blocks as Image”. You might want to use an image editor to crop etc. if required. Then post it here in the community.

yes

Taifun

@taifun
My blocks are all ok but, it is denying the permission of both write and read. What to do?

Did you ask for permission?
Which Android version are you using for your tests?

It would really help if you provided a screenshot your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select “Download Blocks as Image”. You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun

Android 14 @Taifun

Taifun…


@Taifun

In textbox1 there is file name
And yep I asked for permission but it is denying.
I have selected shared scope

But it is denying permission automatically without showing for choosing deny or allow

You are trying to read a non media file, which is not owned by your app
For this you need SAF
See again Some basics on Android storage system

Also permission read external storage does not exist anymore for newer Android versions

Taifun

But that file is created by my app, okay lemme go through that link, thanks for support
@Taifun

In this case set file scope to Shared and use relative path /Download/…

Taifun

@Taifun it’s still getting failed due to denied permission of read external storage. I’m still getting that error.

Show us a screenshot of how you store and read the file, make sure the file does not akready exist before storing it

Also provide a screenshot of the error message

Taifun