Reading file data from a browsed local file

This block works. The weird thing is that it's working for literally any other file that I choose, other than a .txt file..
Here are a few examples:
This "unknown-3.png" image is sitting in the exact same folder as the "TestRoute.txt" file that i'm trying to view.


It does show the file path correctly.

Another example for a file with a different path:

And finally, the "TestRoute.txt" file that I'm trying to view.. it leaves the label empty..

You may need to try this, which works for me on Android 10 (companion). The File component could be looking at the ASD..., so you may have to copy the picked file there (ASD) first in order to be able to read it.

For some reason this did get the path and name correct, but it still could not find the file (the "ReadFrom" function is returning this error:)
image

Here are the blocks (which I copied from you)

Is it because of andriod 11?
Thank you for your help!

Blocks are not quite the same because you are adding an extra .txt to the end of the filename

True, I fixed it and it still doesn't work (Edited the post above)

you are using an Android 11 device
currently the file component only can read from the ASD (and not from a random directory) starting from Android 10
therefore follow this advice

this might change after App Inventor targets SDK30...
for details see this thread Testing the next release of MIT App Inventor (nb187) - #37 by ewpatton

Taifun

You also didn't put a / in front of the filename.....

I have tried to copy the file to the ASD, but even then, the "ReadFrom" function doesn't work..
I started a fresh project with just these blocks and to test it, I still get the error that the file was not found.
I checked if the file was copied successfully, also, I'm displaying the new file path on another label
Here are the blocks:

The result:

I don't quite understand what the SDK30 is and what it will do.. is there anything I can do to get it to work in my current situation or do I have to wait for the new release?

Thank you @Taifun and @TIMAI2 for your help!

your blocks look fine...
which response do you get in the FileTools.FileCopied event?
is the file really there in the ASD where you expect it?

it will bring heavy restrictrions on how to access files in future...
see also @ewpatton's bog here, which has been published 1 year ago
https://appinventor.mit.edu/blogs/evan/2020/08/08/file-path-updates-android-10
which means in your case, probably without using an extension (which still has to be written) it then is not possible anymore to access a file in the /Download folder if your app did not create it, see also the discussion here Testing the next release of MIT App Inventor (nb187) - #187 by Taifun

Taifun

It does show that the copying was done successfully. (I removed the "ReadFrom" function so that it won't override the notification from the FileTools.FileCopied event)

Regarding the SDK30, If I do end up fixing what i have now and getting it to work, it won't matter in the future, right?
Thank you

display the response in a label


and check using a file manager, if the file really is in the ASD

sorry, but SDK30 will bring changes to everyone... including you...

Taifun

Here's the response:

Blocks:

ok, the response is not very helpful...
what about

Taifun

My apologies I didn't notice that line.. sorry!
How do i check it using a file manager? can it be done with the TinyDB? and if so, can you show how to do it if possible?
Thank you for your time and help!

tested (my blocks) using companion on Android 11, doesn't work for me..error 2101 / not found - not reading file from Download folder

I tried to search for a way to do this but I can't seem to get it to work..
I tried to use your "Exists" function from your extension to check whether the file exists, it shows that it does exist in the ASD (unless i don't understand how it works..)
Here are all the blocks:

Here's the block from your extension that I added:

And here's there result:

What can I do at this point? does the file really exist in the ASD and the whole problem is the "ReadFrom" function? or is something else?
If the "ReadFrom" function is the problem, how can I edit it/fix it, or maybe use something else that will actually read the file?

Thank you..

is there a space after the /?
what happens, if you use a text block together with the text /TestRoute.txt to read the file?
Taifun

There isn't a space after any of the /.
By using a text block, do you mean like this?

Nothing different happens.. though, if i do change the /TestRoute.txt to anything, say /TestRote.txt, your "Exists" function still returns true, as if the file exists. but a file named /TestRote.txt clearly doesn't exist.
Edit: I did a wrong test. the "Exists" function works, and it only returns true when checking for the TestRoute.txt file, which was copied to the ASD. so the file is in the ASD it seems, but the "ReadFrom" function still isn't working for some reason...

This will try to read file from /storage/emulated/0/TestRoute.txt which does not exist.

no, because starting from Android 10 the file component reads from the ASD (at least currently, this might change after SDK30)

this works for me (Samsung Galaxy A51 running Android 11)

Taifun

floof.aia (34.4 KB)

1 Like