How do you choose files from ASD and export them?

Dear community,

I had an application in the previous versions that wrote electrocardiogram data files in a predefined folder and users could easily access those files from outside the app, and export them to a PC for example.

In the latest version which prevents writing to the device's memory, I write files to the ASD.

But this directory is not easily accessible by the users. I can use file explorers such as "EStrongs" and it finds the file by deep search, but this is not user friendly.

Is there a way to design an "export" button that opens the ASD folder and user selects the files (with an option to select all) then copies the files somewhere else, or shares the files through whatsapp etc.

An option to delete the exported files to clear the ASD directory would be desirable, please!

THANKS,
SIROUS

Try the ListDirectory method from the file component together with scope = App and use a listpicker to display the file list

See also Storage

To delete a file, use the Delete method

Taifun

You can share selected file with this block

Btw. you still can store files to shared storage including subdirectories, for example /Download/myFolder
See also the overview here

Taifun

1 Like

Btw. you still can store files to shared storage including subdirectories, for example /Download/myFolder

Could you pls write the exact way to write in the "Documents" directory with a subdirectory named "ECG_Save"

I mean the exact text to write as the path.

Here is my block:

1 Like

for the Download folder this should work
/Download/ECG_Save/yourFilename.png
Set the DefaultFileScope in the Screen properties to App. .
EDIT:Should of course be set to Shared to store something in shared storage... however as @Anke mentioned, you have to use Legacy because of a bug...

To store in the Documents folder try
/Documents/ECG... or
/Document/ECG...

Taifun

1 Like

Set the DefaultFileScope in the Screen properties to App .

In this way the application creates a folder named "Documents" in the ASD, then writes inside it!
Changed the file scope to "shared" and "legacy"; did not work.

2 Likes

To save an image with the Canvas component in one of the Shared folders directly you must set DefaultFileScope to Shared or Legacy.

Otherwise set it to App, save the image in the ASD and then move it to one of the Shared folder using the File component or one of the File extensions from @Taifun or @vknow360.

1 Like

save_test.aia (105.4 KB)

Access to shared folder (writing) is not permitted at all.
Lets try a simple code here:

1 Like

Correct, the DefaultFileScope is essentially responsible for two things:

  1. Where are files, created with components that can save something (ie e.g. Canvas), stored.
  2. Which permissions are declared on which Android versions in the Manifest.

To store files directly in the Shared folder /Documents with the Canvas component, DefaultFileScope must be set to Legacy, as this is the only way to declare both storage permissions in the Manifest. On Android < 11 both permissions are required. Unfortunately with AI2 also incorrectly on Android 11+.
I've mentioned this bug countless times.

Yes, this is another bug with the File component, that I also mentioned some times. But anyway, you need to set the DefaultFileScope to Legacy as I said before.

grafik

1 Like

Sorry, but I have tested "legacy" without success.
Let's check everything:
Screen1 properties : DefaultFileScope :Legacy

File1 Properties: DefaultScope; Legacy
ReadPermission TICKED
WritePermission TICKED

Blocks:

When the app is launched:
upon clicking the save button, askes for Permission:

Then this error pops up:

When I go to settings.......permissions:

But altogether, nothing is saved.

1 Like

Try this one: save_test_2.aia (105.9 KB)

1 Like

Your question was to save something using the canvas... so you should use the canvas for your tests... sorry, my previous answer about the default file scope was wrong, I corrected it meanwhile...

testing the file component to save some text will not help for your purposes...

Taifun

2 Likes

Thank you so much. It worked. But I am totally confused.
At 1st installation, it saved without difficulty. but at later times, it could not save. Tried several times, looks like randomly working.
I am very close to give up!

1 Like

I believe you have to delete an existing file in the Shared area before you can save it again. You cannot overwrite.

1 Like

Tried that, no success...

1 Like

As I wrote, you must delete the file before testing with the APK and vice versa.
Because if you first saves the (non-media) file with Companion, the compiled app (APK) cannot overwrite this file because it was created by another app (Companion).

That's why I added this (delete) button:

1 Like

Otherwise (to avoid this prior deletion) you must append a timestamp to the filename.

2 Likes

I don't use companion. I test on my phone. I uninstall the app, delete the file and folder already is created, delete the downloaded apk, then again compile the project...

1 Like

Ok, I understand. Then try this one:
save_test_3.aia (106.8 KB)

It will work always regardless of Companion, APK, un-/reinstallation, removing files, dirs etc.

Blocks

5 Likes