Android Question Writing to files - beyond magic (Epilog)

DPaul

Active Member
Licensed User
Longtime User
Hi,

I have been struggling to write to a text file, and then retrieve the file (copy via USB to desktop).
I was told it would not work with file.dirInternal, but i had to use file.dirrootexternal and write to an SD card instead, which i did not have.
So i purchased a lenovo with SD, and low and behold, the path file.rootdirexternal:
- Produces no errors while debugging (File.WriteString(File.DirRootExternal , "t55bb.txt", "abcxxx")
- checking if file."exists" = true
But the file cannot be found on the sd card! , not anywhere.
It is also not on the tablet (internal)....until, i swich off power to the tablet, power back on, and there it is!
I observed this behaviour a few weeks ago, but now i tested specifically powering off and back on.
Now i'm interested for an explanation.
:)
Paul
 

DPaul

Active Member
Licensed User
Longtime User
Have you tried using the MediaBrowser library and using the ScanNewMedia method?
No, but let me discover what they are.
What I did was to download the ESfile manager to the tablet.
To my surprise, there seem to be 2 "partitions" on the SD card.
One that I can see with the desktop-file explorer (contains the famous lost.dir)
And one that only ES file manager sees, and... it contains the file i'm trying to write !
This still does not explain why i find the file on the tablet as well, which was deemed impossible.

And now i also would like to find a way to "format" the sdcard, to get 1 partition.
This proves to be a tall order, unless somebody knows a trick. I spent all day on this, getting a bit tired...:)
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
I have started wondering if this is a "partition" issue.
I see 2 dirs: sdcard0 (only visible to Es file manager) and sdcard1, visible via usb.
I also see a lot of "emulated" dirs around.
Which is which ?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
notice that on some devices you have an emulated SD card which is actually internal storage.

so that "second partition" might be the actual SD card.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
notice that on some devices you have an emulated SD card which is actually internal storage.

so that "second partition" might be the actual SD card.

Ok, i did not know that.
But how do i get B4A to write to the "real" sd card.
File.dirrootexternal seems to prefer the invisible one !

thx,
paul
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
You should use RuntimePermissions.GetAllSafeDirsExternal to get an array with all the accessible external storages.

OK, i hope we are closing in , on a solution: i did this, and the result is:

Dim rp As RuntimePermissions
Dim folders As List = rp.GetAllSafeDirsExternal ("")
Log(folders)
Log("rootext:" & File.DirRootExternal)
Log("defaultext: " & File.DirDefaultExternal)

(ArrayList) [/storage/emulated/0/Android/data/b4a.example/files]
rootext:/storage/emulated/0
defaultfext: /storage/emulated/0/Android/data/b4a.example/files

So it seems there is only one available path ?
thx,
Paul
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Workaround:
If the file.dirrootexternal is poised to write to the invisible (or emulated?) part of the sd card (sdCard0) , let it.
The desktop will only see sdCard1. Using ES file manager (on the tablet) you can cut and paste the file into sdCard1,
but then the desktop still does not show it, until you have powered the tablet on and off. (???)
So the easiest way is to use ES File manager to see the file in sdCard0, select the file, use the "move" function and
transfer it anywhere you want onto the tablet, even in the root, or to /android....
There the desktop explorer will be able to pick it up.
Is this a state of the art procedure. I doubt it. :) But it does what i want.
If instead of moving, you copy, the sdCard keeps a "backup" for you.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
I have managed to trade my Lenovo (android 5) for a Samsung 10.1, with android 6.01.

Immediately, i ran the exact same code, and monitored expecially the writing-to-file problem.
To my surprise file.dirrootexternal writes now ON the tablet (root) where it CAN be seen and picked up by the desktop windows explorer.
To be sure i even wrote an xml file, perfect result ! (i also had a micro-sd card available, but nothing there)
So my conclusion must be that ,at least the writestring command, is device- and / or android release dependent.
I can only report what i observe. :)
Paul
 
Upvote 0
Top