ChooseFile callback - name undefined

315 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 

Alan Hendry

unread,
Oct 28, 2025, 2:14:03 PMOct 28
to DroidScript
HI,
That discord link doesn't seem to go a entry about this.
Uri2Path is deprecated.
Regards, ah

Dave

unread,
Nov 28, 2025, 5:24:49 AM (5 days ago) Nov 28
to DroidScript
You should'nt require Uri2Path anymore, all the DS methods should support using URI style paths.  

If you find one that does not work with a URI path, then please give us a minimal demo code snippet and we will fix it.

Alan Hendry

unread,
Nov 28, 2025, 6:01:37 AM (5 days ago) Nov 28
to DroidScript
HI,

The docs still say that it returns path,name
But it only returns one value.

FileExists and AddImage don't seem to work.

```
function OnStart() {
    lay = app.CreateLayout( "linear", "top,left" )

    var txt = app.AddText( lay,"test ChooseFile")


    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" )

    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 )
    alert(app.FileExists( path ))
    alert(app.ReadFile( path ))
    img=app.AddImage( lay,path )
    app.OpenFile( path )
}


```

Regards, ah

FrickelPit

unread,
Nov 29, 2025, 1:39:06 AM (5 days ago) Nov 29
to DroidScript
Hi Dave, I append an SPK demonstrating some file functions not working with URIs. Functions behind the red buttons fail. In brackets is a short notice regarding the failure.
Hope that helps and maybe clarifies the issues regarding Uri2Path.
Regards Peter

testUriFileFunctions.spk
Reply all
Reply to author
Forward
0 new messages