Android text message sending

Source: Internet
Author: User
1: Android SMS sending can be simulated in the simulator.
For example, if the ID of the first simulator is 5554,
Run cmd
Telnet local host 5554
Enter help to see many functional commands used in simulators.
GSM call 134343434 // call the current simulator command
SMS send 15555218135 hello, this is a message // is a short message sent to the current Simulator

2: related classes:
Android. telephony. GSM. smsmanager
Android. telephony. GSM. smsmessage
Android. App. pendingintent
Android. widget. Toast

3: ImplementationCode(Excerpt)
String MSG = "hello ";
String number = "1234565678 ";
Smsmanager SMS = smsmanager. getdefault ();

Pendingintent Pi = pendingintent. getbroadcast (SMS. This, 0, new intent (), 0 );
SMS. sendtextmessage (number, null, MSG, PI, null );
Toast. maketext (SMS. This, "Send success", Toast. lenght_long). Show ();

4: Code explanation
The above text message sending code is very simple, but several of the class functions are not easy to understand:

Toast. maketext is a prompt, which is easy to understand;

Pendingintent is an intent description. We can give this description to others.Program, Other programs
According to this description, do what you want to do at the next time. By giving a pendingintent to another application,
You are granting it the right to perform the operation you have specified as if the other
Application was yourself is equivalent to your representative. In this example, other programs send text messages. After the messages are sent successfully, intent should be broadcast.

Function sendtextmessage (string destinationaddress, string scaddress, string text, pendingintent sentintent, pendingintent deliveryintent)
The first three parameters are easy to understand according to the document,
Pendingintent sentintent if the message is sent successfully, sendintent broadcasts the intent described in it. Otherwise, an error code is generated and the message is sent through Android. App. pendingintent. onfinished.
Callback. It is recommended that this parameter be not null, otherwise there may be potential problems of resource waste;
Deliveryintent is the pendingintent broadcast after the message has been delivered to the recipient.

View the pendingintent class. You can see many send functions, that is, pendingintent is performing related operations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.