By calling the phone and SMS functions provided by the Android system, you can send and call messages simply. However, you must configure the relevant permissions in androidmanifest. XML to locate
1 <application
2
3 /application>
On the external layer of the tag, the dialing permission is Android. Permission. call_phone, And the SMS sending permission is Android. Permission. send_sms.
The internal code mainly writes the Click Event of the button, and overwrites the onclick () event.
Send SMS:
1 @ override
2 Public void onclick (view V)
3 {
4 // manage SMS operation classes, such as sending data and text, to obtain objects by calling the getdefault () method;
5 smsmanager = smsmanager. getdefault ();
6 // if the text message content is long, multiple messages are automatically divided and stored in the arraylist;
7 arraylist <string> textsarraylist = smsmanager. dividemessage (conedittext. gettext ()
8. tostring ());
9 // use the for loop to send text messages;
10 For (string text: textsarraylist)
11 {
12 // The sendtextmessage () method of smsmanager is used to send text messages.
13 smsmanager. sendtextmessage (phoneedittext. gettext (). tostring (), null, text, null, null );
14}
15 // This sentence is applicable to messages indicating that the text message has been sent successfully.
16 // toast. maketext (mysmsactivity. This, R. String. Success,
17 // toast. length_long). Show ();
18}
Call number:
1 @ override
2 Public void onclick (view V)
3 {
4 string phonenum = phoneedittext. gettext (). tostring ();
5 // use intent
6 intent = new intent ("android. Intent. Action. Call", Uri. parse ("Tel:" + phonenum ));
7 // enable broadcast intent
8 startactivity (intent );
9}
Both phone calls and text messages Call Android services, but the implementation code is different. When smsmanager. dividemessage () is called, two function messages are sent. You can view the help documentation for senddatamessage and sendmultiparttextmessage. Their declarations and functions are as follows:
public void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a data-based SMS to a specific application port .)
public void sendMultipartTextMessage (String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)
Send multiple texts based on text messages. The text message content has been divided into multiple parts (send a multi-part text based SMS. The callee shoshould have already divided the message into correctly sized parts by callingdivideMessage
.)
I have not studied how to use it.