January 22nd, 2013, 05:43 AM
Client-side implementations (Android VoIP client)
The following article will introduce the code snippets that are new in the mobile applications. These are basically the ones that handle the physical buttons and the rotation features of the mobile devices.
When creating a mobile application, you need to use the File->New->Flex Mobile Project option and set the project name, the target platform (Android, iPhone or BlackBerry)
The following program code (Code 1) shows how you can handle the physical buttons of a mobile device. These instructions should be placed in the creationComplete handler of the application.
Code 1 - Handling the physical buttons of the device
3. NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
4. NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
5. NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
In Code 2 the event handler functions for handling buttons are listed. You can see that there is no difficulty to handle these buttons within the Adobe Flash code.
Code 2 - The event handlers for the device buttons
1. private function handleActivate(event:Event):void
3. NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
6. private function handleDeactivate(event:Event):void
11. private function handleKeys(event:KeyboardEvent):void
13. if(event.keyCode == Keyboard.BACK)
You can distinguish between the horizontal and vertical layout of the mobile devices, too. If the layout needs to be rearranged when the device is rotated, you can do that by defining states in your application and change these states when the device is rotated (Code 3).
Code 3 - Rotation notification for the mobile device
1. private function StageOrientationChange(soce:StageOrientationEvent):void
3. if(soce.afterOrientation=="default" || soce.afterOrientation=="upsideDown")
6. } else
You need to subscribe for the orientation change event in the creationComplete event handler, too. Code 4 shows how you can do this.
Code 4 - Subscribing for the rotation event
Basically these were the functions and instructions that are needed to add in the mobile code but above these the program is the same as the web solutions.
When the programming state is over, you can easily save the code in the proper file format by using the File->Export menu option where you can specify target platform and for example get an .apk file for the Android devices.