Access the Documents file with Cordova.

Just starting out? Need help? Post your questions and find answers here.
Trebor55
Posts: 14
Joined: Fri Mar 07, 2025 8:20 pm

Access the Documents file with Cordova.

Post by Trebor55 »

Good morning,
On Android, can it access the Documents file with Cordova.
If so, how to do it?
THANKS
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Access the Documents file with Cordova.

Post by Caronte3D »

I don't remember which plugin is necessary (not all, probably the first one), but in my app I was imported these 3:

Code: Select all

Import "cordova plugin add cordova-plugin-file"
EndImport
Import "cordova plugin add cordova-plugin-filepath"
EndImport
Import "cordova plugin add cordova-plugin-filechooser"
EndImport
On the github of each plugin you can see JS examples of use:
https://github.com/apache/cordova-plugin-file
Trebor55
Posts: 14
Joined: Fri Mar 07, 2025 8:20 pm

Re: Access the Documents file with Cordova.

Post by Trebor55 »

Good morning,
Thank you but you would not have an example of use with Siperbasic because I do not see how to do
THANKS
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Access the Documents file with Cordova.

Post by Caronte3D »

I checked my app and this is how I access Documents (or others) to load a text file (no Cordova needed).
Try if this works for you:

Code: Select all

EnableExplicit
Enumeration
  #Window
  #ButtonGadget
  #TextGadget
EndEnumeration
CloseDebugOutput()


Procedure ChooseFileEvent()
  
  Define nombre.s, textoArchivo.s         
  
  EnableJS

function cargarArchivo(callback) {

    var inputArchivo = document.createElement('input');
    inputArchivo.type = 'file';
    inputArchivo.accept = '.*';
    inputArchivo.style.display = 'none';
    document.body.appendChild(inputArchivo);

    inputArchivo.addEventListener('change', function(event) {
        var archivo = event.target.files[0];
            v_nombre=archivo.name;

        if (archivo) {

            var lector = new FileReader();
            
            lector.onload = function(e) {
                var contenido = e.target.result;

                localStorage.setItem("contenido", contenido);
                localStorage.setItem("nombre", archivo.name);

                callback(null, contenido);
            };
            
            lector.onerror = function(error) {
                callback(error, null);
            };
            
            lector.readAsText(archivo);
        }
        
        document.body.removeChild(inputArchivo);
    });

    inputArchivo.click();
};

cargarArchivo(function(error, contenido) {
    if (error) {
        console.error('Error al cargar el archivo:', error);
    } else {
      v_textoarchivo=contenido;

  DisableJS
  ; Your filename is in variable: nombre
  ; Your content is in variable:  textoarchivo  
  SetGadgetText(#TextGadget,textoArchivo)
  EnableJS
    }
});
  DisableJS
  
EndProcedure

OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 700, "", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
ButtonGadget(#ButtonGadget, 10, 10, 380, 50, "LOAD TEXT FILE")
TextGadget(#TextGadget,10,70,380,620,"",#PB_Text_Border)
BindGadgetEvent(#ButtonGadget, @ChooseFileEvent())
Trebor55
Posts: 14
Joined: Fri Mar 07, 2025 8:20 pm

Re: Access the Documents file with Cordova.

Post by Trebor55 »

I just tested and unfortunately, it does not work.
I have a blue screen but no display of the window.
By removing the contents of the "Choosefileevent" procedure there is display of the window.
I tested on several smartphones and Android, same result
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Access the Documents file with Cordova.

Post by Caronte3D »

I don't know why doesn't work for you
Use : chrome://inspect/#devices on the Chrome browser (PC) and find what is the error on the developer console (F12)

Here is the apk of the code I posted:
https://drive.google.com/file/d/1hNG_64 ... sp=sharing
Trebor55
Posts: 14
Joined: Fri Mar 07, 2025 8:20 pm

Re: Access the Documents file with Cordova.

Post by Trebor55 »

Your apkfunction perfectly.
So comes from my home
I use the Demo version of Spiderbasic but I have no problem with the creation of other APK.
Your APK is a little over 7mm, mine 4.8MB
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Access the Documents file with Cordova.

Post by Caronte3D »

Trebor55 wrote: Mon Mar 10, 2025 5:28 pm I use the Demo version of Spiderbasic...
I think that could be the problem.
Trebor55
Posts: 14
Joined: Fri Mar 07, 2025 8:20 pm

Re: Access the Documents file with Cordova.

Post by Trebor55 »

Could you tell me if you put special parameters when creating the APK
I have forgotten guidelines
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Access the Documents file with Cordova.

Post by Caronte3D »

Post Reply