ChooseFile callback - name undefined

96 views
Skip to first unread message

Alan Hendry

unread,
Nov 30, 2023, 6:24:19 AM11/30/23
to DroidScript
HI,
In the app docs for ChooseFile the callback is documented as
function(path,name)
name seems to return as undefined
(path returned is path and name)
Android 13, DS 2.61
Regards, ah

function OnStart() {
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    var txt = app.AddText( lay,"Import a file into this project")

    var list = "*/*,application/text,application/apk,application/zip," +
        "audio/mpeg,audio/mp4,audio/ogg,image/png,image/jpeg,text/css," +
        "text/html,text/javascript,text/plain,video/mpeg,video/mp4,video/ogg";
    spnMime = app.AddSpinner(lay,list);

    btnChoose = app.AddButton(lay, "Choose File", 0.5, 0.1 );
    btnChoose.SetOnTouch( btnChoose_OnTouch );

    app.AddLayout( lay );
}
function btnChoose_OnTouch() {
    app.ChooseFile( "Choose a File", spnMime.GetText(), OnChoose );
}
function OnChoose( path,name ) {
    alert( "file path: " + path );
    alert( "file name: " + name );
}



//

Robert Vanleeuwen

unread,
Jun 11, 2025, 7:20:50 PMJun 11
to DroidScript

The question is what to do with URI paths? 

This works with paths selected by a user who manually browses their folder structure and stays away from the quick folder selections in the file picker:

I get this: 

content://com.android.externalstorage.documents/document/primary%3ADownload%2FAPKnHASH%2FCalstar%2Fxdref.db

Parse the name:

var fileName=filepath.substring(filepath.lastIndexOf("%2F") + 3); 
    fileName=decodeURIComponent(fileName); `

Sadly most users will use what's in front of them. They will hit documents or downloads and attempt to open the file there, and that's where I'm stuck. This is the uri most users will pass.... It's the uri given on any quick folder (see screenshot attached):

content://com.android.providers.downloads.documents/document/msf%3A1000033173

Screenshot_20250611_010824_Files.jpg
Ongoing 

Reply all
Reply to author
Forward
0 new messages