As with Android's built in Phone Application, we can call up the SMS Messaging Application in the same way by using an Intent. More often, when employing SMS within an application, we will want our own interface and we can achieve this with the android.telephony.SmsManager class.
In this exercise we will create a simple application that sends a text message to a predefined number.
It is not possible, and may well be illegal, to send SMS messages from an emulator to a real phone. If you intend to test this code on an emulator, then you will need to open two of them.
Either way, start up a new Android project in Eclipse and make your way to the res/layout/main.xml
file. We will need an EditText and a button with the IDs message_text
and send_button
. Here we have also changed the text content: