B4J Tutorial Open external documents

Discussion in 'B4J Tutorials' started by Erel, Nov 27, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    jFX.ShowExternalDocument method allows you to open external documents with the default installed app.

    It expects a single parameter which is the document or resource Uri (link).

    You can use File.GetUri to get the Uri of a local file.

    For example to open a local PDF document:
    Code:
    fx.ShowExternalDocument(File.GetUri("C:\Users\H\Documents""Document.pdf"))
    You can also use it with a non-local resource:
    Code:
    fx.ShowExternalDocument("http://www.basic4ppc.com")
    Caveats:
    -
    This method doesn't throw any error if the resource cannot be opened.
    - You cannot use this method with assets files (files added to the Files tab). It will only fail in Release mode when the files are packaged inside the jar.
    You can use File.Copy to copy it from the assets folder and then open it.

    This method was added in V1.00 beta 6.
     
    GMan likes this.
  2. merlin2049er

    merlin2049er Well-Known Member Licensed User

    Can this be used to open up a folder? I'll give it a try.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Yes. It should work:
    Code:
    fx.ShowExternalDocument(File.GetUri(File.DirApp, ""))
     
  4. merlin2049er

    merlin2049er Well-Known Member Licensed User

    Oh OK, is there an equivalent way to open a folder in b4a?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
  6. merlin2049er

    merlin2049er Well-Known Member Licensed User

    OK, I'll worked around it.
     
    Last edited: Dec 16, 2013
  7. jmon

    jmon Well-Known Member Licensed User

    Hi,

    I am trying to open set a jpg file to an imageView. The Jpg file is on a server (Windows), but I get an error:
    Code:
    java.io.FileNotFoundException: file:\vfx-server-wds\WebServer\intranet\data_users\team1_jo.jpg (The filename, directory name, or volume label syntax is incorrect)
    This is my code:
    Code:
    img.SetImage(fx.LoadImageSample(File.GetUri("//vfx-server-wds/WebServer/intranet/data_users"""), _
                    RS.GetString(
    "teams.team_name").ToLowerCase & "_" & RS.GetString("user.nick").ToLowerCase & ".jpg"3232))
    The file is there. Can someone help me find what's wrong here?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question. It is not related to this thread.
     
  9. ashrafidkaidek

    ashrafidkaidek Member Licensed User

    when i try:

    fx.ShowExternalDocument(File.GetUri("C:\Users\H\Documents", "Document.pdf"))

    I got the error "undeclared variable fx" ... pls let me know how fx should be declared
     
    Last edited: Apr 4, 2014
  10. Erel

    Erel Administrator Staff Member Licensed User

    Is this a UI app?

    fx is part of the default template. You can declare it yourself if it was deleted with:
    Code:
    Dim fx As jFX
     
  11. ashrafidkaidek

    ashrafidkaidek Member Licensed User

    Is this supported for B4A V2.7? because it is not working for me!
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    No. Only in B4J. This is B4J sub-forum.
     
  13. javiers

    javiers Active Member Licensed User

    Hi Erel, is it possible to display a PDF in WebView using this feature?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    No. You can use it to open pdf documents with the default pdf viewer.
     
  15. javiers

    javiers Active Member Licensed User

    Thanks!
     
  16. mc73

    mc73 Well-Known Member Licensed User

    Tried using this method from inside a non-UI app, with no luck. I get:

    Code:
    Program started.
    java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/
    application/Application
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    114)
       at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    82)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    84)
       at b4j.example.main.main(main.java:
    28)
    Caused by: java.lang.NoClassDefFoundError: javafx/
    application/Application
       at anywheresoftware.b4j.objects.JFX.ShowExternalDocument(
    JFX.java:73)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    57)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
       at java.lang.reflect.Method.invoke(Method.java:
    606)
       at anywheresoftware.b4a.shell.Shell.runVoidMethod(
    Shell.java:606)
       at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:227)
       at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:156)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    Program terminated (StartMessageLoop was 
    not called).
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    57)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
       at java.lang.reflect.Method.invoke(Method.java:
    606)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    93)
       ... 
    3 more
    Caused by: java.lang.ClassNotFoundException: javafx.application.Application
       at java.net.URLClassLoader$
    1.run(URLClassLoader.java:366)
       at java.net.URLClassLoader$
    1.run(URLClassLoader.java:355)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:
    354)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:
    425)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
    308)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:
    358)
       ... 
    16 more
    Is it only for a UI app?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Yes. You cannot use jFX from a non-UI application.

    You can use jShell library to start other applications.
     
  18. MikeH

    MikeH Well-Known Member Licensed User

    Can`t get this to work in OSX but works fine in Windows.

    I`ve tried different folders, different Macs, no change.

    Anyone point me in the right direction please?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Use jShell and run "open" with the path as a parameter.
     
    MikeH likes this.
  20. Kevin

    Kevin Well-Known Member Licensed User

    I have made an app in B4J and I got some feedback from someone using Linux and Mac. On Linux (and maybe Mac), trying to open web pages or send emails apparently does not work. This does work on Windows though.

    Code:
    fx.ShowExternalDocument("https://mysite.com")

    fx.ShowExternalDocument(
    "mailto:me@myself.com")


    Apparently the mailto link is opening a blank browser window? She seems pretty tech-savvy so I don't believe it to be something like a lack of default application but I am not 100% sure.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice