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.