free memory on sd card

Cor

Active Member
Licensed User
Longtime User
How to get the free memory on sd card.

Before i download a file i want to detect if there is enough room on sd card?

search forum but could not find
 

Cor

Active Member
Licensed User
Longtime User
Thanks

the following code returns a list of available memory in device

B4X:
    Dim p As Phone
    Dim sb As StringBuilder
    sb.Initialize
   p.Shell("df", Null, sb, Null)  ' free space
    Msgbox(sb.ToString, "Memory:")
 
Upvote 0

Cor

Active Member
Licensed User
Longtime User
so you will get info about only sdcard


B4X:
p.Shell("df", Array As String("sdcard"), sb, Null)  ' free space
 
Upvote 0

francoisg

Active Member
Licensed User
Longtime User
Try the following to return only size of sdcard ... EDIT: Oops, does not seem to work on all devices :-( ---> try the 2'nd function to see if an sdcard is mounted, seems to work on most device ...

B4X:
' *** Returns amount of avalable space on specified device (in kb) ...
Sub GetAvailableSpace (DeviceName As String) As Long
    Dim ph as Phone
    Dim sb As StringBuilder
    sb.Initialize
    ' *** Returns: device_name: xxxK total, yyyyK used, zzzK available (block size nnnn)
    ph.Shell("df | grep " & DeviceName, Null, sb, Null)  ' *** Return free space of specified device only ...
    If (sb.ToString <> "") Then Return Regex.Split("K available", Regex.Split(",", sb.ToString)(2))(0) Else Return -1
End Sub

B4X:
' *** Returns true if the specified device is mounted, false if not ...
Sub GetDeviceAvailable (DeviceName As String) As Boolean
    Dim sb As StringBuilder
    sb.Initialize
    ph.Shell("mount", Null, sb, Null)
    Return (sb.ToString.IndexOf(DeviceName) > -1)
End Sub
 
Last edited:
Upvote 0

rtesluk

Member
Licensed User
Longtime User
Small Demo App

Dec 5 2011
09:20 Hours


Here is a little app to demo stringbuilder and shell("df",null,sb,null)

Regards,

Ray Tesluk :icon_clap:
 

Attachments

  • TweetString20111205.zip
    6.9 KB · Views: 198
Upvote 0
Top