Send data to text file then read with a different App

I am still quite a novice in building apps so hopefully I have described my problem with enough detail and supplied enough supporting information.

I am trying to write some user collected data to a file on the mobile device and then read this data in a different app. I have read a number of posts and tried to make them work but without any success.
I have attached my "Send File" and my "Receive File".
ReceiveDataTest.aia (2.8 KB)
SendDataTest.aia (4.6 KB)
The files is created and stored on the device at /storage/emulated/0/EventData.txt. I can see the file on the device using the file manager and the data does change when I send new data. The receiving file displays the error 2101: the file storage/emulated/0/EventData.txt could not be found.

I have tried adding // or /// to the front of the filename but without success. I have also tried putting the whole path into the filename but without success.
I have also tried changing the default scope of the File component to shared and read/write permissions enabled again without success.

I am trying to get this to work as I plan to integrate it into a more complex set of apps.

Can anyone help me out?

Not really possible. Surprised you can write to a file at /storage/emulated/0/EventData.txt....

Do you really need to have separate apps to do this ?

At the moment I need to send some data to a second app as I have ran in to a compile error which seems to be related to the number of screens in my app and the total number of components. I am trying not to have two apps, but this might be the only way forward.

Hello geordie85

There are a lot of things you can do. No App should have so many screens that App Inventor protests, it gets too complicated to develop and could be too complicated for the User too. So study your design, it may be that you have screens that are identical except for content, in which case you should recycle one screen instead.

What we mostly do however, is to use 'virtual screens'.

Description
When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date.

Analogy
Instead of separate "houses", virtual screens are "rooms" of the same "house".

So, better planning of the App, reducing the number of screens required and using virtual screens - a winning combination.

1 Like

@geordie65
What version of Android are you using?

If you use Android <10, try DefaultFileScope, Legacy.

It is no longer possible to save a non-media file (e.g. data.txt) in the root dir of the external storage on Android 11+. You MUST use one of the Shared folders (/Documents or /Download) or save it in the ASD.

There are a lot of topics related to this. See also here:

He must set DefaultFileScope to Legacy in any case (Android version).
(Of course this is a bug on Android 11+ as I mentioned countless times.)

See also here:

1 Like

He would read the saved data with another app

We don't yet know exactly what the purpose / goal is.
However, if it is to be done with another app, then this app can use SAF for it.

Thanks for all the tips. I am going to try and consolidate what I have so far in order to try and avoid the save and read file.

That's the best approach :sunglasses:

1 Like