B4J Question Default application - getting selected file data

lymey

Active Member
Licensed User
Longtime User
I am trying to create an application (B4J) that can be used as the default application to open a file of specific type, and then process it. i.e using Windows, double clciking on the file afilename.xyz launches my java app and passes the file path and name to the program logic.

I have managed to associate my application by creating a .exe file and using Windows explore to set my application as the default file type. That part works fine, and it launches my application.

BUT - how do I get the details of the file that was selected? :(

(I'm looking for the same kind of functionality as 'get starting intent' in B4A).

Thanks!
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Windows will send the file name to your application as a command line argument which you can retrieve in AppStart() using the Args array.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Note that Args() isn't a String, it's an Array of Strings. You have to access the first argument like so:
B4X:
Log(Args(0))

If you just do
B4X:
Log(Args)
you'll get "Ljava.lang.String;@12345" which is the .toString() method applied to an array. That's the JVM's internal identifier for the array. Not quite what you're looking for.
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
Note that Args() isn't a String, it's an Array of Strings. You have to access the first argument like so:
B4X:
Log(Args(0))

If you just do
B4X:
Log(Args)
you'll get "Ljava.lang.String;@12345" which is the .toString() method applied to an array. That's the JVM's internal identifier for the array. Not quite what you're looking for.

Hahahaha! Duh!:rolleyes:
Thanks Roycefer.

Just in case anyone is as dense as me, here is the correct way of doing it:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
For i = 0 To Args.Length - 1
        Log(Args(i))
Next

Which opens up another question - but I will start a new thread for that
 
Upvote 0
Top