Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Opening Files in Downloads on Android

Author
Message
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 11th Feb 2022 20:38 Edited at: 11th Feb 2022 20:54
So, firstly, very new to AppGameKit but enjoying the journey.

I wanted to load a text (html) file from the Downloads directory on the phone.
To cut a long story short, it didn't work so I set out with the file read/write examples.
To my amazement, this worked, unsure of what was different in my code, I added my file read to the example



The write and the first read all work as expected but the second read to the html/text file fails with file not found.
Yes, the file is there

I can open it with any other editor on the phone along with Chrome, termux to name a few.

The only difference with this file is that it was created by a different application by I thought that pretty much anything in Documents or Downloads was open to all apps.

Can anyone tell me if I am doing something wrong or if this cannot be done??

Any (constructive) comments are welcome

Thanks

PS. Samsung Android 12
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Feb 2022 00:30
i believe android (vs desktop) is case-sensitive (i try to do everything in lower). you're 100% on the filename?
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 12th Feb 2022 00:57
100%, I've even cut and paste the full path to termux and it can see the file (ls) and read it (cat).
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 14th Feb 2022 20:37
Virtual Nomad's suggestion tends to be the most common issue (including the extension potentially being capitalized). Sometimes, an html export will crop the extension to 'htm', so I'd recommend checking that also. If those check out, then perhaps there is something else in place restricting access to operational files vs text files. Does the same thing occur if you name/export/save the file with a 'php' extension, then by the same theory 'txt'?
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 15th Feb 2022 00:41
Thanks for the response but I have tried renaming the file to test.txt for example through a files app but still no joy.
I get the same result in Download or Documents.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 15th Feb 2022 03:48 Edited at: 15th Feb 2022 03:51
which line # is crashing exactly?

Quote: "The only difference with this file is that it was created by a different application"

open it in notepad, save it from there and retry. i'm wondering if the html was saved as something other than utf-8. feel free to attach so we can test, if that's an option. i'm also wondering how BIG the html might be (see below).

and, have you skipped opening the txt files altogether and just attempted the html?

more guesswork:

try isolating the steps. IE, using things like:

If GetFileExists(...) then...

&

If FileIsOpen(1) then...

...at both ends of each file to ensure the previous file is closed and the next one is opened (part of why i don't like using explicit File #'s (or, object IDs, etc))

some theory there is i'm wondering if sdcard access is too slow. you're closing files and immediately opening another (with the same file #) in the OP, for example.
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 15th Feb 2022 03:49
I guess it could still possibly be something related to the file itself and/or the app you used to create it. If you post the file, we could take a look at it. If you create a file within your AppGameKit program by the same filename, can you then open it and read it? And if so, are you able to verify the file is in the exact same location under the exact same name?

I've had some quirky read/write behavior on Android as well, but I don't recall an issue with an invisible or otherwise unavailable file when characters and paths line up.
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 15th Feb 2022 22:13
Thanks again for your help here but I think I'm unlikely to crack it

In answer to your questions, If I call GetFileExists it fails, so I dived straight for the OpenToRead but clearly the same result

I then got thinking about the case of the filename as mentioned above so I ran this noddy piece of code to get file list raw.


and even added permissions just in case. The list of files comes back with one lone file and does not list the html or the txt file.

This leads me to conclude that this must (IMO) be an underlying permissions problem that I can't overcome. I'll just have to try to cloud save it somewhere and pull it down that way avoiding the filesystem.

For info, I've tried it via the AppGameKit player (what a great add-on that is and makes testing soooo much quicker) and as a packed APK. They both produce the same results (as expected I guess).

Thanks again for your assistance, it is much appreciated.
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 15th Feb 2022 22:17
Here is the file. Apart from one large line (encoded image) its 'just' text
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 15th Feb 2022 23:13
Its happy with files written from the same application in Documents and Downloads.


Very noddy test app that happily reads and writes to /sdcard and /storage/emulated/0 .........

I've also attached the code but please don't critique it unless its actually wrong This was a quick knocked up test
CarlGB
6
Years of Service
User Offline
Joined: 20th Jan 2018
Location:
Posted: 15th Feb 2022 23:16
Just for info, the file I was trying to read was written by a random dungeon room generator (someone else's app) which writes it to Download.

Thanks for all your responses but I think I might have to give this idea up. Appreciate all the help given.

Login to post a reply

Server time is: 2024-04-20 06:47:11
Your offset time is: 2024-04-20 06:47:11