Android Question Writing to internal storage

DPaul

Active Member
Licensed User
Longtime User
Hi,

I'm having trouble writing to my samsung 10.1 tablet, internally.
Something like :
Writer.Initialize(File.OpenOutput(File.DirInternal, "Test.txt" , False))...

Have tested all file.* combinations etc., code runs fine, but the test.txt shows up nowhere.
Upon examination it always seems to want to write to "mnt/SD-card.... "
I don't want that, I'd like to select a dir within my tablet that is NOT an SD card.
What don't I understand ?

thx,
Paul
 

DPaul

Active Member
Licensed User
Longtime User
There is almost never a good reason to use TextWriter or TextReader. Use File.WriteString instead.

What is the output of Log(File.DirInternal)? Is the app installed on the sd card?

I'm developing from my desktop via Bridge (wifi) to the samsung 10.1. (no logfiles in sight i 'm afraid.)
Then I execute the app on the device.
For all intents and purposes, the micro-sd is unavailable. The slot has the 3G connection micro-sd.

I tried the file.dirinternal etc route because i read somewhere that it is more efficient.
Maybe the good old "open" and "write" statements will work better.

Paul
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Writing text files to a tablet seems to be an uphill struggle.
Unfortunately it is a showstopper and I just invested in a licence. :-(

Msgbox(File.DirInternal , "xxx")
File.WriteString(File.DirInternal , "t55.txt", "abc")

This code produces no errors, but:
-the path shown seems to have no relationship at all to where the file actually "arrives" = (random?)
-i did read that one is not supposed to see those files with the file manager (nor direct nor via PC), they reside in an invisible region of the tablet.(?)
-but sometimes the file does show up and I can see and open it. Why = mystery!
Any advice ?
thanks,
Paul
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is very simple to write text files.

The first step is to be able to see the logs. If you are using B4A-Bridge then they will only be available in debug mode.
If you don't see the logs in debug mode then you should switch to USB debug mode instead of B4A-Bridge.

i did read that one is not supposed to see those files with the file manager (nor direct nor via PC), they reside in an invisible region of the tablet.(?)
Assuming that the app is not installed on the sd card then File.DirInternal will not be visible to any other app including the PC file manager.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Hi,
Still struggling to write to a file on the tablet, although i switched to USB debugging now.
No SD card involved in the app.

May I paint the broader picture, because I have 2 "connected" problems, and as i have finished part of the code already,
i would like to avoid embarking on the wrong path.

Simplified to the extreme: the user has a tablet, sitting in the jungle all day long. The tablet is showing buttons and perhaps a drop down combo.
The buttons have pictures of animals (lion, tiger, zebra...) and each time he sees one , he pushes that button, and selects (sleeping, eating, just sitting) from the drop down list. Also a timer is active an marks the number of secs since the activity_create.

Problem 1: how do i keep the list in memory, it can become long. For the moment i have declared an array(1000, ...) as string,
but maybe a "list" takes up less resources, and i could save every observation as a string: "56 secs, Lion, sleeping"
Or the SQL option, but that seems to be overkill, look at problem 2.

Problem 2: at the end of the day, this "list" has to be written to an xml file, that needs to be uploaded and processed somewhere else.

What would be the best route ?

Thx,
Paul
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Also a timer is active an marks the number of secs since the activity_create.
You don't need a timer for this. Store the starting time as a process global variable and compare the current time to the stored time.

1. Use a List instead of an array. Assuming that you store strings in the list and assuming that the user will not see more than approximately 5 million animals at a time you will not have any memory issues.

2. You can use XmlBuilder to create the xml file and then save it with File.WriteString. https://www.b4x.com/android/forum/threads/16277/#content
 
Upvote 0
Top