![]() ![]() The capability to send and receive SMS messages is very useful as you can build very compelling applications. In this article, you have seen how you can send and receive SMS messages programmatically from within your Android application. All you need to do is to select each emulator and deploy the application onto each one.įigure 7 Selecting an emulator/device to deploy the application ontoįigure 8 shows that when you send an SMS message to another emulator instance (port number 5556), the message is received by the target emulator and displayed via the Toast class.įigure 8 Sending and receiving SMS messages using the Android emulators Figure 7 shows Eclipse showing the emulators currently running. Deploy the application to each Android emulator. That’s it! To test the application, press F11 in Eclipse. The following code shows how you can invoke the built-in SMS application to help you send an SMS message: If you do not want to go through all the trouble of sending the SMS message yourself, you can use an Intent object to help you send an SMS message. ![]() To view the entire message, click on the message.įigure 4 The SMS message received by the Android emulator Dragging down the notification bar reveals the message received. The message first appeared in the notification bar (top of the screen). Note that for testing using the emulator, when an SMS is successfully delivered, the “SMS delivered” message does not appear this only works for real devices.įigure 4 shows the SMS message received on the recipient emulator. When it is successfully delivered, it will display a “SMS delivered” message. When an SMS is sent successfully, it will display a “SMS sent” message. To send an SMS message from one emulator instance to another, simply launch another instance of the Android emulator by going to the Tools folder of the SDK and running Emulator.exe.įigure 3 shows how you can send an SMS message from one emulator to another simply use the target emulator’s port number (shown in the top left corner of the window) as its phone number. You can now test the application by pressing F11 in Eclipse. The second BroadcastReceiver‘s onReceive event will fire when an SMS is successfully delivered. The second PendingIntent object (deliveredPI) monitors the delivery process. This is where you check the status of the sending process. When an SMS message is sent, the first BroadcastReceiver‘s onReceive event will fire. ![]() The above code uses a PendingIntent object (sentPI) to monitor the sending process. In the AndroidManifest.xml file, add the two permissions – SEND_SMS and RECEIVE_SMS: For example, as sending SMS messages will potentially incur additional cost on the user’s end, indicating the SMS permissions in the AndroidManifest.xml file will let the user decide whether to allow the application to install or not. By doing so, when the application is installed it will be clear to the user what specific access permissions are required by the application. Name the project as shown in Figure 1.įigure 1 Creating a new Android project using EclipseĪndroid uses a permission-based policy where all the permissions needed by an application need to be specified in the AndroidManifest.xml file. To get started, first launch Eclipse and create a new Android project. The good news for Android developers is that you don’t need a real device to test out SMS messaging – the free Android emulator provides the capability to do so. In this article, we take a look at how you can programmatically send and receive SMS messages in your Android applications. Understanding how to use SMS messaging in your application can provide you with many ideas to create the next killer application. In fact, SMS messaging is one great killer application for the mobile phone and it has created a steady revenue stream for mobile operators. It would be safe to say that nearly every mobile phone sold in the past decade has SMS messaging capabilities. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |