AIR Tip 6: This tutorial will walk you through the process of launching an AIR application from the browser and passing arguments into it. This tutorial is current for Adobe AIR Beta 3.
AIR Beta 3 introduced the browser API. This API allows for AIR application to be launched from a web browser, and it also allows for arguments to be passed into the application from the browser.
Setting up Your AIR Application
Applications must set the allowBrowserInvocation value to true to be able to receive events from the Browser API (as illustrated in Code Example 1). Once this value is set, your AIR application will receive a BrowserInvokeEvent [Reference] when it is invoked via the Browser API.
Code Example 1 - Application Descriptor File with Browser Invocation
Knowing the API
The Browser API contains a method, launchApplication, that actually invokes your AIR application [more information]. This application can take three arguments (two of which are required).
Getting Your Publisher ID
The publisherID [Reference] will be the same for each application that is created with a given certificate. This ID can be obtained in two ways:
Creating a Movie to Launch an AIR Application
For a good starting place, you can view the sample install badge that comes with the Adobe AIR SDK. The source for the badge can be found in the src/badge folder. This sample already has the code needed to load the Browser API. This can be seen in Code Example 2.
Code Example 2 - Loading the Browser API (from the Adobe AIR SDK)
The Adobe AIR SDK also contains the code needed to detect if AIR has been installed. We can modify this to display a status message in our custom badge.
Code Example 3 - Detecting AIR (Modified from the Adobe AIR SDK)
You could easily extend this example to also install AIR if it isn't installed (as well as your application), but for this tutorial, we will just launch an application that is already installed. Code Example 4 illustrates how to use the installApplication method to actually launch the application.
Code Example 4 - Detecting AIR (Modified from the Adobe AIR SDK)
Inserting the Launch Badge Into a Page
Code Example 5 shows how to insert this badge into a page using SWFObject. All of the values that are passed to the browser API are passed into the badge with the flashvars that are created with the JavaScript SWFObject method so.addVariable.
For this example, I have passed the applicationID and publisherID into the movie with flashvars, but there might be situations where you don't want to expose all of this information. In those cases, you can hard code these values into your movie.
Code Example 5 - Inserting the Launch Badge Into a Page with SWFObject
Testing the Example
For the sample to work properly, you will need to have the BrowserInvokeEvent Sample AIR Application from AIR Tip 5. You can install this application here.
Exercise Files
Download (15 kb)
Reference
Getting the application and publisher identifiers (Developer Guide)
Checking from a web page if an AIR application is installed (Developer Guide)
Launching an installed AIR application from the browser (Developer Guide)
Loading the air.swf file (Developer Guide)
[...] Deploying Adobe AIR applications seamlessly with the badge install feature Launching an Application from the Browser [...]
[...] SOAP Webservice (AIR Beta 1) AIR Tip 5: Passing Arguments to an Application on Install (AIR Beta 3) AIR Tip 6: Launching an Application from the Browser (AIR Beta 3) AIR Tip 7: Using Command Line Arguments (AIR Beta 3) AIR Tip 8: Serializing Objects [...]
[...] 来源:AIR Tip 6: Launching an Application from the Browser [...]
[...] Launching an Aplication from the Browser [...]
Hi,
I have followed all examples and managed to open my AIR app by clicking on a flash applet in the browser.
I have also managed to call a function of a flash applet, by clicking on another flash applet.
However I was not able to call a function of my AIR app by clicking on a flash applet. Is this even possible?
I am using the following code in the AIR app:
var lc:LocalConnection = new flash.net.LocalConnection();
lc.connect(“myTestConnection”);
and this in the flash applet:
var conn:LocalConnection = new flash.net.LocalConnection();
conn.send(“myTestConnection”, “myTestFunction”);
the same (AIR) code seems to work when in a second applet but not for the AIR desktop application…
[...] Useful links: http://www.davidtucker.net/2008/01/11/air-tip-6-launching-an-application-from-the-browser/ [...]
Hi,
Thanks for the gr8 tutorial, Can you guide me in executing local application (say windows notepad) from adobe AIR application.
I am not finding any source code / help for this on internet.
Hi, I read your book as well as the online articles here but I haven’t found a solution for the following problem:
I want to invoke an Air app automatically from the Browser after the user successfully logged in to a specific site.
It looks like executing the .launchApplication() function checks back if it’s triggered from a click event and I don’t know how to cheat that one yet.
So, any ideas on that one?
Thanks a lot!
- Michl
David,
We are trying to figure out where to get the Publisher ID for AIR help files and cannot. Adobe says they don’t support the product. Can you please tell me how to get this ID? I’m not sure what you mean by the NativeApplication.nativeApplication.publisherID.
Thanks and regards,
J. Napoli
Hi David,
I am new to AIR. I tried to open a installed AIR app from browser by following the tip but no luck. what I did is as following.
1. Installed Tip11-1.air downloaded from your tip 11.
2. Unzip airtip6 and webshare the example folder.
3. Changed the applicationID and publisherID in the index.html to point to Tip11.
so.addVariable( “applicationID”, “net.davidtucker.airtips.LaunchApplication1″ );
so.addVariable( “publisherID”, “C3AD24548343F7569498274306102AB328526006.1″ );
4. Browse to index.html file, I can see the flash detected air installed, but when I double click it, it stucked at “Attempting to Launch AIR Application”.
Also I tried to install the tip6 sample app, but I got “Invalid argument: IP 203.99.129.1″
Could you please help out to see if I misunderstood or missed something? thank you very much in advance.
Bob
@Bob – after I wrote this article there was a change to the API. The Browser API only allows alpha-numeric characters. If you were to format the IP in a different manner (without the periods) – the error should go away.
Hi David,
What IP are you talking about? I just point the applicationID and publishID to the a installed AIR app, I didn’t specify any IP address.
thanks.
Hi David,
Is it possible for browser to find out if a certain AIR application is running or not?
thanks
Hi David,
I have an AIR app installing from the browser. However, when the user clicks the launch button in my swf (which is a home-spun badge essentially), I get a dialogue that says “Open”, “Save” and “Cancel”. I want to get rid of the “Save” button as the direct download approach doesn’t accept custom params… or so it seems.
Any tips you might have would be welcome.
thanks.
Hi David,
Can I use this way to install/launch native installer application (instead of air)? My application is using the NativeProcess class. When I tried to put appurl as EXE, I got “The application could not be installed because the installer file is damaged.” error.
Thanks.
Hi David
I am trying to use this on AIR 2.0. I couldnt get this to work correctly. I think there is no requirement of a publisher ID, etc on AIR 2.0 and this is causing issues.
Thanks!
All Developer Guide links under References are broken.