Using custom URL schemes

Specifying a custom URLs allow an application to be woken up when a specific URL is selected on a device. For example, the custom URL could be a home URL of the application web page.

Creating the sample stacks

This lesson uses 2 stacks,

1. The "launchee" stack, which is launched by a custom URL

2. The "launcher" stack, which calls the URL causing the first stack to launch.

The "launchee" stack can also be launched by entering the URL in a web browser.

The Launcher Stack

The "launcher" stack consists of 3 buttons which launch various URLs. The custom URL of the "launchee" stack is "webme" and any URL beginning with that string will launch the app. The rest of the URL can contain arguments or extra information that can be used by the "launchee" stack.

The script of the top button is

on mouseUp
    launch url "webme://"
end mouseUp

The other also use the launch url command.

The Launchee Stack

This is the stack that is launched, it has a field to display the the URL that caused it to be launched and a button that uses the mobileGetLaunchURL function to display the URL.

The script of the button is

on mouseUp
    local tURL
    ## This function returns the URL that was used to launch the application.
    put mobileGetLaunchUrl() into tURL
    answer tURL with "Okay"
end mouseUp

The urlWakeUp message

The "launchee" stack also handles the urlWakeUp message. This message is sent to an app when it is launched via a custom URL, it has 1 parameter, wakeUpString, which is the URL that launched the app. The "launchee" stack handles this message in the card script.

on urlWakeUp pURL
    ## This message is received by the app when a custom url is used to launch the app
    put pURL into field "url"
end urlWakeUp

Setting the Custom URL

An app's custom url is specified the the iOS or Android pane of the Standalone Application Settings. In this example the custom URL we want to use is "webme".

Launching the app from the Launcher stack

Deploy both stacks to your simulator or device, open the "launcher" stack and click any of the buttons. The "launchee" stack will open and the URL you selected will be displayed in the field. If you click the "Get Launch URL" button and answer dialog will be shown displaying the URL.

Launching the app from a browser

Once the "launchee" app is on your device you can also launch it from a browser, by going to any URL that starts with the custom URL of the app.

4 Comments

Barry G. Sumpter

Nice!
Is there a way for the launchee to send back a message to the Laucher with data or perhaps a "Successful" or "Unsuccessful" message directly?

Hanson Schmidt-Cornelius

Hi Barry,

I am not aware of a way to implement this directly.

If the Launcher is still running as the main application, after the Launchee was called, then you may want to assume that the launch action was unsuccessful.

Alternatively, you could try this:

Using parameters you send to the Launchee as part of the URL to control its behaviour, it should be possible for the Launchee to launch the Launcher again. This would indicate that the Launchee is accessible and was lunched. In this case the Launcher and the Launchee would have to be registered with individual custom URLs. Don't think this is the most elegant approach though, as the user would see the launches of the applications.

Kind Regards,

Hanson

Barry G. Sumpter

Hi Hanson,

Many thanks for the reply.

I've found the Laucher app is still in the process thead and can't be exited until after the launchee app has been exited.
I think thats an Android rule. Unless there is a special command in LiveCode so the laucher app can reliquish process control to the lauchee app.

I've setup a Path and File name parameter to send to the lauchee app. As to where to save any info I want to communicate between the two.

I've setup a timer in the Laucher app to check 10 times for the existance of that path and file name every 3 seconds.

Certainly not the most eligant approach either but works for me at the moment.

Hanson Schmidt-Cornelius

Hi Barry,

that is a very interesting approach and it saves you launching the launcher stack again. Would not have considered that.

LiveCode does not offer a command to relinquish control.

Kind Regards,

Hanson

Add your comment

E-Mail me when someone replies to this comment