Storing a simple file outside of the application specific directory (ASD)

Hi,
I've been looking for a solution for my problem since several days now. It looks so simple, but it gets more and more complicated.
My situation: I have a first version on my app, where I build up a database (TinyDB) with some measurements of my personal health. As a second version I want to add more functionality (some predictions and / or calculations) into it using the data that I have collected with the first version. So once I have the second version ready, I want to take over the data from the first version.
The simplest solution would be to store the data in a simple file on my phone ouside of the ASD. But that seems to be impossible in a packaged app (in companion it works!)
Does anyone have an idea?
I use a Galaxy A51 with Android 10.

Try using SAF:

generally if you want to use 2 different apps store the file using the first app in shared directory /Download or /Documents, see also the overview

and read the file using the second app as @vknow360 already said using the SAF extension

however if I understand you correctly, you are talking about only one app, but 2 different versions... which means, you can store the data in TinyDB and after installing version 2 of the same app the data in TinyDB still will be there...

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

What does "second version" mean?
It should actually mean that the second version only differs in the version code (and more functionality) from the first version, but has the same packageName (project name, e.g.: myHealth.aia). Otherwise it would be a new app.

Show your blocks (especially where you store data, TinyDB).

My app consists of 2 screens. Screen1 Enables entering, changing, and searching measurements, ScrMyData handles the basic data. Screen1 has > 2200 blocks, ScrMyData has > 600 blocks. Therefore I only include snippets here.
I have now changed all file related properties to shared:
grafik
grafik

Here the respective blocks for the storing of the file:
grafik
grafik
grafik

I now get Error 908: the permission WRITE_EXTERNAL_STORAGE has been denied.

Set DefaultFileScope to Legacy in the Designer:

grafik

and post your blocks again in high qualitiy, see here (point 3).

1 Like

Creating the file works now after I changed the file and path to:
grafik

Thank You!

Sorry, that was an error. It produces Error 2103: The file /storage/emulated/0/Documents/BE_Dokuv00_01.txt could not be created.
So still unsolved.

Post the aia or a test aia.

And here my blocks in better quality:
grafik
grafik


grafik

Yes, the File component needs a relative path, see here: Some basics on Android storage system.

1 Like

I changed it, butI still get Error 2103

Please find the aia below:
BE_Doku_v00_01_04.aia (107.3 KB)

Since the text file was already created with the Companion App (i.e. another app), the file cannot be deleted or recreated (saved) with the APK. The file name must be changed beforehand.

Try this:
grafik
and do not run the app with Companion. Just build the APK and try.

Note:
You can also add a timestamp to the filename then it would work with Companion and the APK too.

1 Like

This was successful. But for some reason or another the File.Delete doesn't work or I have misunderstood it. I did the following
grafik
Do you know, what happened or is wrong?

Did you try it with the APK or Companion?

I used the apk. (And I wrote the second 'If', because I suspected that my delete statement doesn't work as I expected.) BTW I also tried it with FileScope Legacy. Then the file was not found - as expected.
Coding it as I posted, the error label looks like that:

File exists
File deleted
File exists anyway

That's why I'm asking

@Briefmark, unfortunately you ignored my previous answer

as well @Anke's question

so if my understanding is correct, what about just using TinyDB?
Taifun

It should work.

  • What is the file name and was the file created (with the APK)?
  • Did you change the project name (aia)? (If so, then it would be a new app that cannot access the file.)

EDIT:

  • Did you uninstall the app beforehand? If so, the reinstalled app is also a new app that cannot access the file.