Page 1 of 3
Access the Documents file with Cordova.
Posted: Sun Mar 09, 2025 9:17 am
by Trebor55
Good morning,
On Android, can it access the Documents file with Cordova.
If so, how to do it?
THANKS
Re: Access the Documents file with Cordova.
Posted: Sun Mar 09, 2025 12:07 pm
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
Re: Access the Documents file with Cordova.
Posted: Sun Mar 09, 2025 8:49 pm
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
Re: Access the Documents file with Cordova.
Posted: Sun Mar 09, 2025 9:41 pm
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())
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 4:05 pm
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
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 4:22 pm
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
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 5:28 pm
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
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 5:44 pm
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.
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 7:12 pm
by Trebor55
Could you tell me if you put special parameters when creating the APK
I have forgotten guidelines
Re: Access the Documents file with Cordova.
Posted: Mon Mar 10, 2025 7:51 pm
by Caronte3D