Some clarification about writing to external storage (sd card)

jschuchert

Active Member
Licensed User
Longtime User
I have been testing all the aspects of my application, including writing to an external file. The following code is representative of what I have been using.
B4X:
If chkmultinvWriter.Checked =True Then
filename=txtfilename.Text 
Msgbox("A file named " & filename & " will be created for your use. See manual for details","Write to sd card")
writer.Initialize (File.OpenOutput (File.DirRootExternal ,filename,True))
writer.Write("MULTIPLE INVERSE ROUTINE" & CRLF & CRLF)
writer.Write ("Point range = " & txtrange.Text & CRLF )
writer.Write ("Inverses " & CRLF )
writer.Write(txtdisplay.Text )
writer.Close 
End If

I had assumed since it was being written to 'dirrootexternal' that it was being written to the sdcard. I found out that is not the case. It is still internal on the device. That's fine because when I connect via usb, I can transfer those files to my computer and it works great. So if the internal storage of the device is full, how would files be written to the sd and bypass internal? I am guessing that the typical use of an sd would be to transfer music, videos and movies to a device. My tablet has 4gb of internal storage so I doubt I will ever need anything else but I suppose I am not a typical user. Thank goodness I have a device to work with to learn all these things before I release my app to the public.

Jim
 

agraham

Expert
Licensed User
Longtime User
"External" mmory is not necessarily removable memory Data Storage | Android Developers. I don't know if any Android devices, other than the Xoom, have been released that support both internal "external" memory and removable memory. On the Xoom the SD card is not yet supported by Android so it can only use its internal "external" memory, but at least it has 32Gb of it :cool: . I guess the Android team are still working on the problem of how to integrate both sorts of mermory in a transparent way.
 
Upvote 0

kolbe

Active Member
Licensed User
Longtime User
On the dell streak7 wifi, DirRootExternal gives the internal 16GB on /mnt/sdcard. Mounted on sdcard is sdcard2 which is the SD card memory or /mnt/sdcard/sdcard2. The streak7 is froyo.

What I'm not sure about is that the internal 16GB seems to be partitioned with a 2GB partition as DirInternal. I have also seen that apps can be moved to the external memory but I haven't tried if this and I don't know if this means the SD card or just the other internal partition.

Rather confusing all is.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
nd I don't know if this means the SD card or just the other internal partition.
Most probably the other internal partition. DirInternal is the secure area where apps and their data live. DirExternal is insecure and open to all apps to access.
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
The Asus TF101 Transformer has a folder called "sdcard", but also supports removeable storage in the form of a microSD slot in the device, and an SD slot in the keyboard attachment along with two USB ports which happily support memory sticks, USB hard disks and so on. These are found in a folder in the same tree as "sdcard" called "removeable". I can access these with several file explorers, but the sqlite editor I just downloaded from the app store insists it can't look anywhere except "sdcard" for databases because my device is not rooted.

The Transformer is selling like hot cakes, so I have a feeling that how to address removeable storage is going to be a hot issue. I haven't written my first program yet, but I've been reading the guides and this Forum for days and haven't come across anything that explains this - yet.

Caravelle
 
Upvote 0

priusfan

Member
Licensed User
Longtime User
accessing MicroSD on Asus transformer TF101

Bonjour Caravelle,

I had the same question regarding access to micro Sdcard.

So I made some tests just now...

yes it works:

compare the 2 following lines (both are working):

B4X:
' DataLogger.Initialize(File.OpenOutput(File.DirRootExternal , "/Sniffer/sniffer_"&DateTime.date(now)&"_"&DateTime.time(now) &".txt", True))
 DataLogger.Initialize(File.OpenOutput( "/Removable/MicroSD/Sniffer","sniffer_"&DateTime.date(now)&"_"&DateTime.time(now) &".txt", True))

it works the same way for USBkeys on the dock
the one front left is called USBdisk2
the one back right is called USBdisk1
so you replace MicroSD in previous example by USBdisk1 or USBdisk2
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
Thanks a lot, or even merci mille fois.

I shall try this out with the example in the Text Files tutorial amended appropriately and see what happens. Fingers crossed...

Caravelle
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
Excellent ! This works very well, thank you <so> much. That's one of my key issues solved

I have printed up an index card as follows:

STORAGE LOCATION PATHNAMES (ASUS TF101)
to access internal SD card:
FileDirRootExternal & "/dirname" & "filename"
to access removable MicroSD card:
"/Removable/MicroSD/dirname/filename"
to access removable SD card in keyboard dock:
"/Removable/SD/dirname/filename"
to access right back USB storage (USB1):
"/Removable/USBdisk2/dirname/filename"
to access left front USB storage (USB2):
"/Removable/USBdisk2/dirname/filename"

I think I shall try to write a program which will copy/transfer selected files in any of these locations to one of the other locations. I did much the same in B4PPC for my Ipaq214 primarily so that it could be used as a dump for camera CF cards when they get full when I am away from home.

Thanks again

Caravelle
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Excellent ! This works very well, thank you <so> much. That's one of my key issues solved

I have printed up an index card as follows:

STORAGE LOCATION PATHNAMES (ASUS TF101)
to access internal SD card:
FileDirRootExternal & "/dirname" & "filename"
to access removable MicroSD card:
"/Removable/MicroSD/dirname/filename"
to access removable SD card in keyboard dock:
"/Removable/SD/dirname/filename"
to access right back USB storage (USB1):
"/Removable/USBdisk2/dirname/filename"
to access left front USB storage (USB2):
"/Removable/USBdisk2/dirname/filename"

I think I shall try to write a program which will copy/transfer selected files in any of these locations to one of the other locations. I did much the same in B4PPC for my Ipaq214 primarily so that it could be used as a dump for camera CF cards when they get full when I am away from home.

Thanks again

Caravelle


In the quote I've colored some text in orange and red. In reference to these items -- question: Shouldn't the first one (orange) read "USBdisk1" and not as it does?
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
Just a simple and obvious typo. Corrected my index card as soon as I spotted it.

Caravelle
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
external removable memory

Asking users in a file dialog for the location of the external sd-card is no good idea, because this will overtax their abilities in most cases.

Suggestion: couldn't we use this thread to post the external removable memory locations of all our devices, to get a complete list of all possible sd-card locations? In this manner it would be easy to write a function, that retrieves the sd-card location of any device.

Asus TF 101 SD Card locations were already mentioned by Caravelle,
here are the external removable memory locations of my devices:

Asus A500 MicroSD: /mnt/external_sd
Asus A500 USB: /mnt/usb_storage
Asus A500 USB Drive: /mnt/usbdrive

Samsung Galaxy S2 Micro SD: /mnt/sdcard/external_sd
Samsung Galaxy S2 USB: /mnt/usb

What about Samsung Galaxy Tab 10.1 and other new devices?
Anybody?
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
You don't need, and shouldn't use, an absolute filepath to the external memory. Android gives it to you with File.DirRootExternal.

???

File.DirRootExternal is fine, as long as the removable sdcard is reachable in this folder or in a subfolder.

Can you explain me, how i can access the external removable sdcard on my A500 tablet without knowing the absolute filepath???

It's not a subfolder of File.DirRootExternal. It is mounted separately as mnt/external_sd

That's why a list of absolute filepaths would be helpful.
 
Upvote 0

hdtvirl

Active Member
Licensed User
Longtime User
A500

I have never been able to see the SDcard in my A500 using any tools.

I have an adapter for my Laptop toread/writeto the microsd card and I have neverbeen able toread anything off it.

BOB.
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
I have never been able to see the SDcard in my A500 using any tools.

I have an adapter for my Laptop toread/writeto the microsd card and I have neverbeen able toread anything off it.

BOB.

You can't see it from Windows, because only File.DirRootExternal is visible to Windows. But you can use the sdcard in your program when you know the absolute filepath, which is "/mnt/external_sd".
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Google seemd to have intended that on Honeycomb and later devices with one or more easily removable SD card the SD card would be accessed via the media APIs which can protect the cards contents against unexpected removal by a user who fails to unmount the card. Accessing the card through the normal flat file system does not offer any protection and unexpected removal can corrupt the card contents. As a consequence of this Honeycomb devices look like a media device to PCs and transfers are made using Media Transport Protocol so their storage does not need unmounted for access by a PC.

On the "official" unadorned Google version of Honeycomb 3.2 on my Xoom the SD card is visible in the flat file system but is read-only to applications although a PC can read and write it as a media device. There is a new media files API that applications can use to write arbitrary files to the card as well as read them and I have written a library that can do that. Unfortunately it is not possible to create new folders on the card, only write to existing ones. This might be intentional as media files are normally segregated into standard folders or it might be an oversight - no-one seems to know.

For whatever reason different Honeycomb device vendors seem to have come up with differing mount points and different access permissions for their removable storage. It is likely that Gogle will address this with the release of Ice Cream Sandwich. Unfortunately I can find no statement by Google about the intended use of removable storage on Honeycomb and later which is a pity as a clear statement would make the position a lot clearer than it is at the moment.
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
Unfortunately I can find no statement by Google about the intended use of removable storage on Honeycomb and later which is a pity as a clear statement would make the position a lot clearer than it is at the moment.

Thank you for your research on this issue.

In my application, I have to deal with large amounts of audio data, which is usually located on a removable sdcard. In the meantime, before there is an official solution like File.DirRootRemovable or something like that:

My idea for a workaround was writing a GetSDCard-function which tries to to find the sdcard with a list of known absolute filepaths.

Is this advisable as a workaround?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Is this advisable as a workaround?
Depends ! :)

For an app that will run on a known device or set of devices where the user accepts responsibility for removing the SD card at an appropriate time it is fine IMHO.

For an app in the Market I would say it's premature until it's clear how Google intend to standardise the use of removable storage. But of course that solution has to propagate to a sufficient installed base before the app would be viable. However it's your choice in the end!
 
Upvote 0

hdtvirl

Active Member
Licensed User
Longtime User
SD Cards et al

Thanks Guys, that's sorts a problem out for me too.

"/mnt/external_sd/" Acer A500

Regards

BOB
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
This is my GetSDCard Function in it's current state. I would like to extend the list of known locations and would highly appreciate it, if some other forum members would post here the sdcard location of their tablet devices.


B4X:
Sub GetSDCardFolder() As String
'*************************************************************
'Try to find the location of removable external sdcard memory,
'perform a write test and return the folder name, if writable.
'*************************************************************
Dim root As String
Dim folder As String
Dim sdf As String

  '------------------------------------
  ' Acer A500 Tablet
  '------------------------------------
  [COLOR="Blue"]root = "/mnt"
  folder = "external_sd"[/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If
  '------------------------------------
  'Samsung Galaxy S2
  '-------------------------------------
  [COLOR="blue"]root = File.DirRootExternal
  folder = "external_sd" [/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If
  '-------------------------------------
  ' ASUS TF 101 (Micro SD)
  '-------------------------------------
  [COLOR="blue"]root = "/mnt/sdcard/Removable"
  folder = "MicroSD"[/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If
  '------------------------------------
  'Asus TF 101 (SD-Card Keyboard Dock)
  '------------------------------------
  [COLOR="blue"]root = "/mnt/sdcard/Removable"
  folder = "SD"[/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If
  '-------------------------------------
  'HTC Desire
  '-------------------------------------
  [COLOR="blue"]root = File.DirRootExternal
  folder = "sd"[/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If
   '-------------------------------------
  'MOTOROLA DROID 3
  '-------------------------------------
  [COLOR="blue"]root = "/mnt"
  folder = "sdcard-ext"[/COLOR]
  If File.IsDirectory(root,folder) Then
    sdf=root & "/" & folder
    If Writetest(sdf) Then Return sdf
  End If

 'to be continued....
End Sub
Sub WriteTest(dirname As String) As Boolean
Dim s As String    
  Try
    File.WriteString(dirname,"test.tmp","test")
    s=File.ReadString(dirname,"test.tmp")
    File.Delete(dirname,"test.tmp")
  Catch
    Log(LastException.Message)
    Return False
  End Try
  If s="test" Then return true
End Sub
 
Last edited:
Upvote 0
Top