Page 1 of 1

Accessing files on Android internal file system...

Posted: Wed Sep 11, 2024 4:30 pm
by Caronte3D
Android App related:
It's posible to list the files in the Downloads directory of the smartphone, and read a text file to work with?

I found this, but seems not to work:
viewtopic.php?t=2285

Thanks in advance ;)

P.D:
This example in the documentation works on PC (Chrome) but not in Android .apk

Code: Select all

;
; ------------------------------------------------------------
;
;   SpiderBasic - File example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;


Procedure ReadCallback(Status, Filename$, File, Size)
  If Status = #PB_Status_Loaded
    Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
    Debug "Reading first 3 lines:"
    
    ; Read the first 3 lines
    ;
    While Eof(0) = 0 And NbLine < 3 
      Debug ReadString(0)            
      NbLine+1
    Wend
    
    CloseFile(0)
    
  ElseIf Status = #PB_Status_Error
    Debug "Error when loading the file: " + Filename$
  EndIf
EndProcedure

Procedure OpenFileRequesterCallback()
  If NextSelectedFile()
    ReadFile(0, SelectedFileID(), @ReadCallback(), #PB_LocalFile)
  EndIf
EndProcedure

Procedure ChooseFileEvent()
  OpenFileRequester("text/plain", @OpenFileRequesterCallback())
EndProcedure

OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a text file...")

BindGadgetEvent(0, @ChooseFileEvent())


Re: Accessing files on Android internal file system...

Posted: Sat Sep 14, 2024 7:58 am
by Caronte3D
Is very frustrating the fact we can't use files in the smartphone :(
I found a ridiculous solution: Upload the files to a server and access those files through her link

Re: Accessing files on Android internal file system...

Posted: Sat Sep 14, 2024 8:13 am
by plouf
its android os limitation, they need special permitions which get higher and higher every while,
thus something worked yesterday will NOT work tommorow

more or less nowdays its only possible to access your OWN assets in your OWN sandboxed program dir ..

Re: Accessing files on Android internal file system...

Posted: Sat Sep 14, 2024 8:33 am
by Caronte3D
But many, many program let you load files as you want :?

Re: Accessing files on Android internal file system...

Posted: Thu Sep 26, 2024 7:52 am
by Caronte3D
Solution (for me at least):
viewtopic.php?t=2652

Re: Accessing files on Android internal file system...

Posted: Sun Oct 06, 2024 5:20 pm
by tj1010
OpenFileRequester() uses cache despite what flag you use. It's working here Windows 11 Chrome and Android 14.

To actually do file operations without a browser cache you got to use a Cordova module, and even then there are around five permissions you have to manage. The apps you see that use device file system transparently use the ART or Xcode file system API, or for Cordova apps one of the libraries..

You can also write your own Cordova modules to do anything the Xcode or ART APIs allow.. For example, right now you can't do lower level TCP/IP stuff with anything on Cordova hub, but you can write a Cordova module to do it, because IOS and Android runtimes have APIs for it..

Re: Accessing files on Android internal file system...

Posted: Mon Oct 07, 2024 9:00 am
by Caronte3D
tj1010 wrote: Sun Oct 06, 2024 5:20 pm You can also write your own Cordova modules to do anything...
If we had an easy to follow tutorial... ;)