The file component relies on WRITE_EXTERNAL_STORAGE
to write stuff, but TaifunFile doesn't.
And because WRITE_EXTERNAL_STORAGE
doesn't exist in Android 11, the file component does not work for writing to external storage, even on shared folders.
Ok, I see, I will go back to that then. I was thinking in the new update Taifun's Taifun File work would have been rolled into the the FileStorage block stuff, but maybe that is future.
Wait a minute here, TaifunFile, does not have a read file block? How can you use it then on subdirectories within /Download? That is broken with the built in FileStorage blocks!
Thanks,
Jonathan
Maybe you need to ask for READ permissions:
But I would try without this first.
You can use the file component to save a file in ASD and then move it to a shared folder using taifun file.
The file component works ok in ASD.
Updated guide to version 2.
Great idea! I will keep everything in the Shared storage, copy it into the ASD as a working copy to open it, then copy it back to Shared after saving and delete my working copy. I think that will work.
I'm not sure that's needed. I'd try working directly with the file in the shared folder.
Yes, this another bug with the File
component. This method (File.MakeDirectoy
) requires WRITE
permission (it must be declared in the Manifest).
But the storage permissions are declared this way:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If you remove android:maxSdkVersion="29"
from the Manifest, it will work.
But this doesn't make sense at all, because WRITE
permission does no longer exists on Android 11.
@ewpatton
Yes, I actually just gave up on reading and writing anything to the shared folders currently including the workaround suggested by anonwins. I implemented the workaround suggested by anonwins above, but instead of using the ASD used the /Download, folder as my workspace as the read file block works great in /Download but no further. So I copied the file from /Download/Test/abc.txt to /Download/abc.txt, edited the text saved it, and then copied it back to /Download/Test/abc.txt. (I would delete the files once copied both directions). This works great in the companion. However, as soon as I install it as an app, I get the permission errors. This is even after checking their boxes, and explicitly asking for permission in the initialize block. I am going back to working just in the ASD.
If you remove
android:maxSdkVersion="29"
from the Manifest, it will work .
But this doesn't make sense at all, becauseWRITE
permission does no longer exists on Android 11.
That is good to know, however, because of the whole bundling thing, I had to eliminate my manual APK edit. (The one I had been using was android:hasFragileUserData="true") As I haven't found a simple way to unpack and edit the manifest in a bundle. (If that is a quick win for anybody at MIT Appinventor, I can't think of anyone who would not want the option of keeping their data when uninstalling a app!)
I will attach the currentcopyToSharedTest2.aia (58.8 KB) .aia if anybody else is interested in playing with it. (It is still based off of yours Anke.)
@anonwins I now did some tests using /Download
and /Documents
.... while the following blocks work for me in the companion app it unfortunately does not work anymore after building the app on Samsung Galaxy A51 running Android 11
trying to copy a text file from the assets to
/Download
or /Documents
...the file will not be copied and the Exists method displays the following message
same for the /Documents
folder
Attached the example project filetest.aia (34.2 KB)
Taifun
PS: my tests here are able to copy a file to /Download
using the file component, but this still fails for /Documents
, which is an already known bug to fix...
I just build and installed your filetest.aia, changed nothing, and it works without the slightest problem:
OK now I found what goes on. It's not something new. It's been mentioned by @Anke multiple times. Let me try to say it simply: files saved in shared folders, belong to the installation of the app that created them. other apps (or even a re-installation of the same app) cannot overwrite them. So it will give you these permission errors (EACCES) if the installation of the app is different than the one that created the files in the first place.
The problem is not only for overwriting/deleting the file though. I still haven't managed to read its content.
It appears that we cannot:
- read a saved file in shared folder (file component says not found)
- overwrite/delete a saved file in shared folder if A) we reinstall the app, B) using another app
I haven't tested with DefaultFileScope:Legacy though. If I understand right, these problems just go away when you switch to legacy. Haven't tested. (edit: they don't. see the following link)
Check my latest guide on working with shared folders (written today).
you mentioned, you are using an Android 11 device for your tests, which one?
yes, I'm aware of that, but it looks like I forgot to delete it from the Download folder before starting the test...which means, copying to /Download
works for me now...
however copying to /Documents
still fails
I would like to invite others to test, too... what do you get?
here is the apk file to download https://drive.google.com/file/d/1a98oQiPNIoYijpkjLpkc48jwu0iR8e9X/view?usp=sharing
Taifun
For me they always work the same (documents and download).
I have a Redmi 7, LineageOS 18.1, Android 11
In other news, I made a TaifunFile/FileComponent front-end myself today: TSF File Operations
edit: screenshots v1.1
If you give it a try, I'm sure it can help you figure out things quickly
Also there are a few things missing, like file listing, perhaps I'll make a new version soon lol.
Fun fact: the name of the project is still filetest_copy so technically this is the app that you started
If you want to inspect/edit it: filetest_copy(1).aia (148.1 KB)
edit: get version 1.1 from google drive
Try to copy WooHoo.txt
from the assets to /Documents/WooHoo
2.txt.
ok, your project works both for /Download
and /Documents
...
but only once... if I delete the file file.txt
from /Download
and /Documents
and try to copy again then the error appears... it is not possible to copy again using the same filename... and the Exists method returns false in this case...
yes this seems to work... which means, you can use the filename only once... and after deleting the file it does not work anymore... interesting...
Taifun
If the file was deleted by the app itself then there is no problem, but I was pretty sure you removed that file manually.
yes exactly
Taifun
So that means that each installation has an internal "file memory" which makes it think that there's a file where one isn't any more? (If the user deletes it) Really interesting indeed. It would explain the weird behaviour of the file component when it is used to create files but taifun can't see them and the opposite. (In the File Operations app you can see it by creating/deleting/exists with taifun & component).