Phone call in Air Android
Air for Android has the ability to integrate mobile services. I will be showing an example of how make phone calls using the ‘tel:’ protocol with Actionscript 3. The method used for making a phone call is the navigateToURL(). The Actionscript 3 code will look like this.
var req:URLRequest = new URLRequest(‘tel:012345789’); navigateToURL(new URLRequest(req));
When the code is run in an app, the mobile will start the call with the specified number using the mobile’s OS. In my example I will have an input text field to display to the phone number to be called, and a button to start the call. To use the ‘tel:’ protocol you need to select the ‘INTERNET’ checkbox in the Permissions tab in the Android settings, or you can manually enable this feature using the application descriptor file.
<android>
<manifestAdditions>
<![CDATA[<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>]]>
</manifestAdditions>
</android>
Firstly, open a new Air Android file and save it with the name: PhoneApp. Then create a new AS3 class file with the name: PhoneApp and set it as the document class of the FLA file. In the PhoneApp class file add the following code.
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.*;
public class PhoneApp extends MovieClip
{
private var font1:Font1 = new Font1();
private var telephoneTf:TextField;
public function PhoneApp()
{
//Create title textfield
var titleFormat:TextFormat = new TextFormat(font1.fontName, 25, 0x000000);
var titleTf:TextField = new TextField();
titleTf.x = 120;
titleTf.y = 154;
titleTf.antiAliasType = AntiAliasType.ADVANCED;
titleTf.embedFonts = true;
titleTf.defaultTextFormat = titleFormat;
titleTf.text = 'Enter phone number';
titleTf.width = titleTf.textWidth + 5;
titleTf.height = titleTf.textHeight + 5;
addChild(titleTf);
//Create input textfield
var telephoneFormat:TextFormat = new TextFormat(font1.fontName, 44, 0x000000);
telephoneFormat.align = TextFormatAlign.CENTER;
telephoneTf = new TextField();
telephoneTf.x = 50;
telephoneTf.y = 200;
telephoneTf.width = stage.stageWidth - 100;
telephoneTf.height = 53;
telephoneTf.antiAliasType = AntiAliasType.ADVANCED;
telephoneTf.embedFonts = true;
telephoneTf.border = true;
telephoneTf.defaultTextFormat = telephoneFormat;
telephoneTf.type = TextFieldType.INPUT;
telephoneTf.restrict = "0-9 +()";
addChild(telephoneTf);
//Add call button
var callBtn:CallBtn = new CallBtn();
callBtn.x = 157;
callBtn.y = 301;
callBtn.addEventListener(MouseEvent.CLICK, btnClicked);
addChild(callBtn);
}
private function btnClicked(e:Event):void
{
if(telephoneTf.length > 0)
{
var urlRequest:URLRequest = new URLRequest("tel:" + telephoneTf.text );
navigateToURL(urlRequest);
}
}
}
}
When the input text field is selected inside your mobile device, the mobile’s OS will open up the keyboard for a phone number to be entered. The call button will make a phone call with your mobile device’s Phone app.



0 comments:
Post a Comment