Developing Android Applications with Adobe AIR [7]
mailButton.addEventListener(MouseEvent.CLICK, mailMe);
addChild(mailButton);
}
function createSprite(hue:int, xPos:int, yPos:int):Sprite {
var temp:Sprite = new Sprite();
temp.graphics.beginFill(hue, 1);
temp.graphics.drawRect(0, 0, 200, 100);
temp.graphics.endFill();
temp.x = xPos;
temp.y = yPos;
return temp;
}
function callMe(event:MouseEvent):void {
trace("calling");
navigateToURL(new URLRequest('tel:18005551212'));
}
function textMe(event:MouseEvent):void {
trace("texting");
navigateToURL(new URLRequest('sms:18005551212'));
}
function mailMe(event:MouseEvent):void {
trace("emailing");
navigateToURL(new URLRequest
('mailto:veronique@somewhere.com?subject=Hello&body=World'));
}
}
}
Select Control→Test Movie→Test to compile the application. You should always run your code on the desktop before installing it on a device in case you have syntax errors.
Using Flash Builder
The code is the same.
Select the small black arrow to the right of the Run button, and then select Run Configurations. Under Mobile Application, select Main if it is not selected. The “Target platform” should be Google Android. Under “Launch method”, select “On desktop” and choose your device from the pull-down menu. Click Run to compile and create the mobile application. If you don’t see your device listed, you can add it manually.
NOTE
For Windows users, if you see the name of your device in the list, it indicates that the necessary drivers are preinstalled. Otherwise, make sure to install them.
Packaging Your Application As an APK File and Installing It on the Device
Let’s go over the process of packaging and installing your application on the device.
Using Flash Professional
To package the application as an APK file in Flash Professional and install it on the Android device, follow these steps:
Go to File→AIR Android settings.
Under the Deployment tab, do the following:
For the Certificate, select your AIR code-signing certificate if you already have one. To create a temporary one, click Create and fill out the form. At this stage, the only important field to remember is the password because you will need to enter it again shortly. We will discuss what a certificate is in Chapter 4.
For the Android deployment type, choose “Device release”.
Under the “After publishing” section, select both “Install application on the connected Android device” and “Launch application on the connected Android device”.
Select File→Publish. At this point, an APK file is created, which you can see on your computer. The APK file is installed on your device, and the device launches the application.
Using Flash Builder
To package the application as an APK file in Flash Builder and install it on the Android device, follow these steps:
Right-click on your project folder and select Properties.
Select ActionScript Build Packaging→Google Android→Digital Signature→Certificate. Select your AIR code-signing certificate if you already have one. To create a temporary one, click Create and fill out the form. At this stage, the only important field to remember is the password because you will need to enter it again shortly. Click OK.
Go back to Run Configurations. Under the launch method, select “On device” and then click Run. At this point, an APK file is created, which you can see in your project. The APK file is installed on your device, and the device launches the application.
NOTE
If this is the first time you are launching an AIR application on your device, the Adobe AIR license agreement will appear. You only need to agree to the terms once.
If you are familiar with developing AIR applications on the desktop, you may have noticed a difference here. The warning dialog does not appear on the device upon installation. Instead, Android displays the list of permissions your application subscribed to.
Testing and Debugging
The Adobe remote debugging session uses either USB (recommended) or WiFi, hence our Internet permission setup earlier.
For networking, turn on WiFi on the device and