Tuesday, January 3, 2012

How to Send SMS From a Web Server to an Android Phone Using Java

The Java "wireless.messaging" library provides Android developers with a method to send SMS messages using the Java language. An SMS message is a text-based message you send to another phone number. Text messaging is a basic service offered by wireless services. You must specify a phone number to send the message and the "sms://" protocol to trigger the right services on the Android device.

Difficulty:Moderate1

Open the Java Eclipse software development program on your desktop. Open the Android project in which you want to add an SMS module. Double-click the Java file you want to use to send the message.

2

Add the wireless messaging library to the top of the file. You need this library to call the necessary functions. Copy and paste the following import statement to the top of the file:

import javax.wireless.messaging.*;

3

Create a connection to the wireless phone number. The following code sets up a variable with the target phone number:

this.connection=(MessageConnection) Connector.open("sms://5555555555:2948");

The "2948" is the port number used to run the SMS service. Replace the "5555555555" with the mobile phone number you want as your recipient.

4

Set up the message content. The following code sets up a string variable with the content "Hello, Recipient" as the message:

String message ="Hello, Recipient";

5

Send the message. The following code packages the SMS message and sends it to your recipient phone number:

this.connection.send(message);

Read Next:

Copyright © 1999-2012 Demand Media, Inc.
Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy. Ad Choices en-US


View the original article here

No comments:

Post a Comment