Android Question Flash drive

David Riley

Member
Licensed User
Longtime User
I bought B4A to rewrite a data logger I wrote in VB6. It requires the data to be written to a removable flash drive.
The kitkat dictate of only accessing files in Android/data/b4a.example/ does not seem to present a problem.
However I don't see how to address the secondary external storage and create the file and directories. Please would someone write me a few lines of example code that will work on Nexus 7 to get me started.
Thanks.
 

EddyW

Member
Licensed User
Longtime User
Ok thought he mean the internal SD Card because most tablets cant use a external USB drive (so far i know)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Ok thought he mean the internal SD Card because most tablets cant use a external USB drive (so far i know)

I have an Samsung Galaxy Note 3 Tablet 10,1 and it HAS two SDCards like my Phone. An internal and an external.
I found the folder like suggested in above thread under /mnt/sdcard/exStorages/SdCard but it may vary in different devices...
 
Upvote 0

David Riley

Member
Licensed User
Longtime User
I'm going round in circles. I cannot find anything with B4A that sees the flash drive.
Using a Nexus 7 2013, otg cable and 4GB drive. OTG Disk Explorer Lite is letting me look at files and directories.
If kitkat only allows reading or writing in Android/data/MyAppName/ , how do these directories get created ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should be able to create the folder yourself. Note that it is not MyAppName. The folder is based on the package name.

There is a new method in Android 4.4 that allows you to get the path:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array(Null))
   For Each p As Object In paths
     Log(p)
   Next
 End Sub

Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0
Top