Accessing files on Android internal file system...

Just starting out? Need help? Post your questions and find answers here.
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Accessing files on Android internal file system...

Post 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())

User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

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

Post 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
plouf
Posts: 295
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

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

Post 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 ..
Christos
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

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

Post by Caronte3D »

But many, many program let you load files as you want :?
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

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

Post by Caronte3D »

Solution (for me at least):
viewtopic.php?t=2652
tj1010
Posts: 218
Joined: Wed May 27, 2015 1:36 pm
Contact:

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

Post 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..
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

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

Post 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... ;)
Post Reply