Android calls and sends text messages

Source: Internet
Author: User

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.

 

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.