Load files on Android App (and more...)

Share your advanced knowledge/code with the community.
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Load files on Android App (and more...)

Post by Caronte3D »

Here is a snippet of code to load files on Android App, Web App, etc...
This is a workaround because normal file access in SpiderBasic gives me an error (on Android App), maybe by system limitation.

Comes from this thread: viewtopic.php?t=2640

Feel free to modify and use it as you want ;)

Code: Select all

; Snippet to read file on Android App and Web App (iOS untested)

Procedure OpenRequester()
  
Protected result.s=""

EnableJS
function LoadArchive(callback) {
    var inputFile = document.createElement('input');
    inputFile.type = 'file';
    inputFile.style.display = 'none';
    document.body.appendChild(inputFile);

    inputFile.addEventListener('change', function(event) {
        var File = event.target.files[0];
        if (File) {
            var lector = new FileReader();
            
            lector.onload = function(e) {
                var contenido = e.target.result;
                callback(null, contenido);
            };
            
            lector.onerror = function(error) {
                callback(error, null);
            };
            
            lector.readAsText(File);
        }
        
        document.body.removeChild(inputFile);
    });

    inputFile.click();
};
DisableJS

!LoadArchive(function(error, contenido) {
!    if (error) {
!      v_result="Error loading file";
       Debug result
!    } else {
!        // Here you can process the archive content =========
!        v_result=contenido;
       Debug result
!    }
!});

EndProcedure

OpenWindow(0, 100, 100, 320, 200, "Test Read File",#PB_Window_ScreenCentered)
ButtonGadget(0,80,50,160,100,"Open")

BindGadgetEvent(0, @OpenRequester())
tj1010
Posts: 218
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Load files on Android App (and more...)

Post by tj1010 »

This still uses JIT and cache under HTML5. I posted code here a while back that actually does real Android and IOS directory and file operations, but the Cordova module it used has changed. There are around five modules on Cordova hub that allow real device file and folder operations, but on Desktop>Browser you'll always need to use this HTML5 method that can only do persistence if the cache policy allows it..

I don't think most people here realize what you can do with Cordova modules and API.. Pretty much anything Android>ART and Xcode allows; which is basically everything.. If it's not on Cordova hub it can be made with Cordova API and a few programming languages with very little code. TPM auth, Samsung KNOX enterprise features, full Accessibility API, All BT profiles, low level TCP/IP, both cameras(I've posted code for this before), WIFI(also posted code for this), non-CORS HTTP requests etc..

The only thing I can think of you can't do is weird chipset stuff like the WLAN chip going in to monitor mode without a jailbreak..
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Load files on Android App (and more...)

Post by Caronte3D »

Thanks for your point of view, I'm sure we need many more examples of using Cordova, for me trying to use it is almost like being blind and trying to hit a target with a dart :lol:
Quin
Posts: 118
Joined: Wed Nov 08, 2023 4:38 pm

Re: Load files on Android App (and more...)

Post by Quin »

Caronte3D wrote: Mon Oct 07, 2024 7:05 am Thanks for your point of view, I'm sure we need many more examples of using Cordova, for me trying to use it is almost like being blind and trying to hit a target with a dart :lol:
Agreed, Cordova seems scary. Sounds powerful though, now my interest has been peeked :D
Post Reply