B4J Question Default application - getting selected file data

Discussion in 'B4J Questions' started by lymey, Jul 13, 2015.

  1. lymey

    lymey Active Member Licensed 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!
     
  2. Roycefer

    Roycefer Well-Known Member Licensed 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.
     
  3. lymey

    lymey Active Member Licensed User

    Thanks - that's what I thought, but the Args() string doesn't seem to pass any valid data, for example:
    .
     
  4. Roycefer

    Roycefer Well-Known Member Licensed User

    Note that Args() isn't a String, it's an Array of Strings. You have to access the first argument like so:
    Code:
    Log(Args(0))
    If you just do
    Code:
    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.
     
  5. lymey

    lymey Active Member Licensed User

    Hahahaha! Duh!:rolleyes:
    Thanks Roycefer.

    Just in case anyone is as dense as me, here is the correct way of doing it:
    Code:
    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
     
Loading...