Android Question Trying to create a file in Internal directory

chuck3e

Active Member
Licensed User
Longtime User
I'm connected through WiFi to a real device with no external SD card. The following code is not creating a file in internal storage that I can find. The Log does show the values that should be going to storage. I am assuming the file should be there after the program is terminated and I turn on usb storage.

B4X:
Sub Process_Globals
   
  Dim CountWrong(15)     As Int
    Dim kvs As KeyValueStore
End Sub

Sub Globals
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    'Activity.LoadLayout("splash")
   If FirstTime Then
      kvs.Initialize(File.DirInternal, DateTime.Now&"Counts")
   End If
   
    For i = 1 To 14
    CountWrong(i) = 0
    Next
   
    CountWrong(1) = 100
    CountWrong(2) = 200
    CountWrong(3) = 300
    CountWrong(4) = 400
    CountWrong(5) = 500
    CountWrong(6) = 600
    CountWrong(7) = 700
    CountWrong(8) = 800
    CountWrong(9) = 900
   
   
    For i = 1 To 14
'    'put a "simple" value
      kvs.PutSimple(i, CountWrong(i))
   'fetch this value
      Log(i&" "&CountWrong(i))
    Next
End Sub
 

chuck3e

Active Member
Licensed User
Longtime User
I just tried it again by installing an SD card and replacing DirInternal with DirDefaultExternal but it still doesn't show up on the SD card.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Erel, I have discovered the reason for my confusion. Apparently Log(File.DirDefaultExternal) does not go to my tablet's SD card but goes to an 8G area of my tablets internal memory that it considers "external". It goes here regardless of whether the SD card is inserted or not. I know this because that's where my Counts file is ending up, and I can find it using the tablet's file manager and Windows Explorer when USB Storage is turned on.

When I specify DirInternal I can't find the file anywhere using the tablet's file manager or Windows Explorer, but it's somewhere, because I can use the Log command to display the results of PutSimple and GetSimple within the application. I believe, in this case, it is going to that area that is accessible only to the application and for the life of that application.

So the reason for my confusion is because I thought my tablet's internal memory was Internal when in reality its internal memory is External. I'm glad I cleared that up (in my own mind anyway [insert smiley face here])

Thanks for your guidance. It's amazing how you can solve most of our problems with one sentence or less.
 
Upvote 0
Top