Detailed Guide: URL Handling
JWrapper supports an API for cross platform integration with operating system URL handling. This allows you to define a custom protocol such that when a link is opened in a browser with this protocol your app is opened to handle it.
For example if you wanted your app to be opened to handle when the user clicked on a "myapp" type link in the browser like:
myapp://mybase/one/two?paramOne=one¶mTwo=two
then on OSX and Windows you can register using registerURLSchemeForVirtualApp (Windows, MacOS) These methods both have the same parameters and do the same job:
schemeProtocol - this is the custom URL protocol ("myapp" in the example above) that you want to register
virtualApp - this is the virtual app that should be opened to handle any attempts to open URLs of the above type
Once registered your specified virtual app will be opened on demand to handle any link clicks on that type of URL. When opened your virtual app can then call getRequestedURL (Windows, MacOS) to get the exact URL opened, including any parameters.
For example if you wanted your app to be opened to handle when the user clicked on a "myapp" type link in the browser like:
myapp://mybase/one/two?paramOne=one¶mTwo=two
then on OSX and Windows you can register using registerURLSchemeForVirtualApp (Windows, MacOS) These methods both have the same parameters and do the same job:
schemeProtocol - this is the custom URL protocol ("myapp" in the example above) that you want to register
virtualApp - this is the virtual app that should be opened to handle any attempts to open URLs of the above type
Once registered your specified virtual app will be opened on demand to handle any link clicks on that type of URL. When opened your virtual app can then call getRequestedURL (Windows, MacOS) to get the exact URL opened, including any parameters.
Advanced URL handling on MacOS
On MacOS you can also configure your app to listen to URL opens while your app is already open. To do this you can run through the following few steps:
// First get the .app bundle ID
String appBundle = JWSystem.getAppBundleName();
String bundleID = JWConstants.buildOsxDomainFromBundle(appBundle);
// Register this bundle ID for jwsample://... urls.
JWMacOS.registerAppAsURLHandler("jwsample", bundleID);
// Add an OS X event listener, which is called every time a getURL request is received by JWrapper.
JWMacOS.getMacOSInstance().setOSXEventListener(new JWOSXEventListener()
{
public void openURL(final String url)
{
// Process the URL here.
}
});
On Windows this isn't possible directly since Windows doesn't support it however a dedicated URL-handling virtual app which then communicated the URLs to your main app would achieve the same result.
// First get the .app bundle ID
String appBundle = JWSystem.getAppBundleName();
String bundleID = JWConstants.buildOsxDomainFromBundle(appBundle);
// Register this bundle ID for jwsample://... urls.
JWMacOS.registerAppAsURLHandler("jwsample", bundleID);
// Add an OS X event listener, which is called every time a getURL request is received by JWrapper.
JWMacOS.getMacOSInstance().setOSXEventListener(new JWOSXEventListener()
{
public void openURL(final String url)
{
// Process the URL here.
}
});
On Windows this isn't possible directly since Windows doesn't support it however a dedicated URL-handling virtual app which then communicated the URLs to your main app would achieve the same result.