Problem with create Dir & Save txt file

Hi everyone
I have encountered a problem that seems to be easy and I have tried different solutions but the result is the same as the first.
I'm going to save a text file to a default directory, it looks like the job was done correctly but after the build the directory remains in the correct location but the text is saved to Android / data.

I will send the pictures for guidance and I thank you in advance

:point_up:
thank you

You're writing to the external storage but that's not allowed in the new API. There are exceptions: the shared storage. These are folders accessible by all apps. /Music, /Downloads, etc. You CAN write to them with TaifunFile, but you need to change your file paths to begin with file://

Do it like this and it will work:

I advise you to write in /Documents. You can also create subfolders. Just tested and it works. :v:

If your app worked some days ago, it's because AI2 recently changed API target like 3-4 days ago. I was baffled by this too.. "But it worked fine!" I thought. But it turns out that's the way things are going to be, nice and tidy and categorized. Music files in /Music, documents in /Documents, etc. Seems good to me. Of course the the AI2 team will eventually provide more ways to write to external, but for now, it's the only I could find.

My app home screen image


This method did not work either
I also tried different methods that other friends said but it didn't work.
Like the pictures below
This Image
&
This
& kodular: https://community.kodular.io/t/some-basics-on-android-storage-system/69074?u=bodymindpower

Can friends help me with this?
Thank you in advance
IMAN

you are not able to copy a file to an arbitrary directory anymore after the SDK30 release...

I do not know how @anonwins was able to copy a file to a shared directory using the file extension, see also my tests here API 30 workarounds v2 - #19 by Taifun

but you can copy a file to the shared storage /Download using the file component, see my test project here

Taifun

Working with shared folders, 28/09/21

@Program_maker

See my reply here API 30 workarounds v2 - #20 by anonwins

So the moment you re-install your app, say bye-bye to your writing capabilities of the files that you have saved in shared folders.

So my guide works only if you keep your current app installed (no reinstalling, no installing other version, etc). Of course without reading capabilities in shared folders none-soever. A good practice then would be to only work with files in ASD, and just EXPORT to a shared folder. Because the "exported" file cannot be accessed any more. (It can be overwritten or deleted though, until you reinstall the app). You can't read from the "exported" file at all.

Keep in mind you can't overwrite if you reinstall the app, so you should make sure the file doesn't already exist. For example, timestamp it: /storage/emulated/0/Documents/MyNewFile-1630121307.txt or just use TaifunFile.Exists (it works even on reinstalled apps) and then save by another name if it exists.

All in all, when you "export" your file, you should forget about it. It's saved and out of your control.

Note also: because you can't read the "exported" file, you can't copy it back to ASD for working with it. So make sure you keep a copy of it in ASD from the beginning. So you can export another one easily.


ASD (Application-specific Directory)

:white_check_mark: TaifunFile can write, overwrite, delete
:white_check_mark: TaifunFile can check if file exists
:white_check_mark: File component can read, write

Shared folder (eg. /Documents or /Download)

:white_check_mark: TaifunFile can write
:warning: TaifunFile can overwrite or delete (but not if app is reinstalled, or if using another app)
:white_check_mark: TaifunFile can check if file exists
:x: File component cannot read/write, or even see files
:white_check_mark: Extensions which don't rely on WRITE_EXTERNAL_STORAGE permission can read files

*Where you see TaifunFile, it means also all extensions/components that don't rely on WRITE_EXTERNAL_STORAGE permission. (TaifunMusicPlayer, Pro Camera, etc)


This table makes it obvious that you cannot work in shared folders. Things will break. But you can always work in ASD and export to shared. This makes sense. This is why the ASD exists.

Android tell you "here's your playground (ASD), do anything you want in there, i don't mind. but in the shared folders, you're not the boss. you can't just delete another app's things. you can't just edit another app's things. mind your own business in the shared folder. you wanna go crazy? get crazy in your ASD, buddy!" :rofl:

For android, each version of an app is another app. Heck, even each installation of an app is another app.

Hope this little guide clears things. It's been a mess these days.

You see, this is good practice. Because in the shared folders, the user is the boss, not an app. You can't read/overwrite in shared folders, and that's good. This is privacy & security, and makes me happy to know my phone secures my data from being overwritten/deleted by weird apps.

Keep in mind that extensions like TaifunMusicPlayer can read files in shared folders. You can request a song to play. It's just that the file component is kinda broken now and can't read files in shared folder, but in theory, android allows it.

DefaultFileScope:Legacy

I just ran some tests using this option. It seems to enable file reading in shared folders using the file component. But if the file is created by another app, or another installation of the same app, then you can't read it using the file component. So it doesn't really help. You can't rely on it. Am I right, miss @Anke?

@Taifun

Seems now the problem is that the file component can't read files in shared folders.
But TaifunPlayer can. Is there maybe some way to implement the same approach in another extension, to be able to read the contents of files in shared folders?

How is it able to read files even after reinstallation? I guess it calls an internal system player which apparently has full permissions to read from external storage. If that's the case, then dismiss my request.

Thank you

Tested on Android 11:

1 Like

:white_check_mark: TaifunFile can write into /Download, :x: but not into /Documents, see here API 30 workarounds v2 - #21 by Taifun
:white_check_mark: File component can write into /Download, :x: but currently not into /Documents, see the bug report here Test "copy file from assets to shared directory and read it from there" in ai-test - #6 by Taifun

my guess is, you are testing the file component... :+1:
which means, writing in to /Download even into a subfolder works fine...

Taifun

2 Likes

Nice app. I made a similar one based on TaifunFile today. Perhaps you'd like to check it. It allows you to test relative/absolute/full paths too. Can you share yours? Thanks

Very weird, for me it treats /Documents the same as /Download.

1 Like

Yes, in combination with your TaifunFile extension.

That was interesting

I was going to do a math process that I used to do in Windows programming, a process like this:
1: Save the file to a directory such as a download / document
2: Build a directory as before
3: Transfer or copy the file saved in the download / document directory
4: Delete the file from the source directory

The interesting thing is that by the AI Companion, everything seemed to be right, but after downloading, everything was different

thank you

If possible .aia put the version to use and learn

Peace be upon you Anke - taifun - anonwins

1 Like