ChooseFile callback - name undefined

451 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 PM6/11/25
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 PM10/28/25
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 AM11/28/25
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 AM11/28/25
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 AM11/29/25
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

FrickelPit

unread,
Dec 18, 2025, 1:15:56 AM12/18/25
to DroidScript
Hi Dave, sorry to bring up the tiresome topic of file functions using URIs again. I'm wondering if I'm missing something or if I simply didn't get a response to my last post concerning the SPK testUriFileFunction. In your post from November 28, 2025, you said: "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."
My SPK shows, using examples, that the file functions CopyFolder, FileExists, FolderExists, DeleteFolder, ZipFile, and ZipFolder fail with URIs, while the file functions CopyFile, DeleteFile, ReadFile, WriteFile and RenameFile work with URIs. (currently using DS 2.79.1) This can be verified at any time in File Explorer once the SPK is run and observed in debug window.
If you add `uri = app.Uri2Path(uri)` as the first statement in the `function onPermission(uri)` of my SPK, the program works perfectly except for the `ListFolder` file function, which apparently only works in scoped storage.
I would really appreciate a reply and remain, with kind regards,
Peter

Dave

unread,
Jan 18, 2026, 5:04:10 AMJan 18
to DroidScript
Hi Peter, sorry for the slow response and thanks for your demo/test script.

I'm overloaded with work right now, but should be able to focus more on this issue in a couple of weeks time.  Please remind me again if I do not get back to you in two weeks.

The internal code used by app.Uri2Path(uri) is meant to be deprecated on recent versions of Android, what version are you using?

FrickelPit

unread,
Jan 18, 2026, 6:07:19 AMJan 18
to DroidScript
Hi Dave,
glad to hear from you. I'm on Android 15 now and app.Uri2Path(uri) still works faultless. If you have time to look into this issue, please check if my posting https://groups.google.com/g/androidscript/c/LyWSSCjuDlY/m/94_R63DvAQAJ makes some sense or if I'm completely wrong.

FrickelPit

unread,
Feb 7, 2026, 4:42:26 AM (5 days ago) Feb 7
to DroidScript
Hi Dave, you asked for a reminder about this. Here it is. I'm sorry you're so busy.
Reply all
Reply to author
Forward
0 new messages