B4J Tutorial Open external documents

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:
B4X:
fx.ShowExternalDocument(File.GetUri("C:\Users\H\Documents", "Document.pdf"))

You can also use it with a non-local resource:
B4X:
fx.ShowExternalDocument("http://www.b4x.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.
 

jmon

Well-Known Member
Licensed User
Longtime 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:
B4X:
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:
B4X:
            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", 32, 32))
The file is there. Can someone help me find what's wrong here?
 

ashrafidkaidek

Member
Licensed User
Longtime 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:

mc73

Well-Known Member
Licensed User
Longtime User
Tried using this method from inside a non-UI app, with no luck. I get:

B4X:
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?
 

MikeH

Well-Known Member
Licensed User
Longtime User
Yes. It should work:
B4X:
fx.ShowExternalDocument(File.GetUri(File.DirApp, ""))

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?
 

Kevin

Well-Known Member
Licensed User
Longtime 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.

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

fx.ShowExternalDocument("mailto:[email protected]")



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.
 
Top