Create Text Message

The URLRequest class can be used to open the Messaging application to send text messages. By prepending the request with sms:, you will tell Android to launch the Messaging application when the navigateToURL method is called. Figure 6-3 shows the sample application running and Figure 6-4 shows the Messaging application with the phone number pre-populated. Unfortunately, at this time it is not possible to send a message along with the phone number when using the Messaging application:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark">

    <fx:Script>
          <![CDATA[
               protectedfunction sendIt_clickHandler(event:MouseEvent):void
               {
                     var s:String = "";
                     s += "sms:";
                     s+= sendTo.text;
                     navigateToURL(new URLRequest(s));

               }
          ]]>
    </fx:Script>

    <fx:Declarations>
          <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:Label text="Send To" top="40" left="50"/>
    <s:TextInput id="sendTo" top="30" left="160" text="2125559999" width="250"/>
    <s:Button id="sendIt" label="Send" click="sendIt_clickHandler(event)" top="110" 
        left="160"/>
</s:Application>
Open a text message in the Messaging application

Figure 6-3. Open a text message in the Messaging application

The Messenging application has opened

Figure 6-4. The Messenging application has opened

Get Developing Android Applications with Flex 4.5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.