Summary of Android SMS sending methods

The SMS manager class is provided in the Android API to handle SMS. The sendtextmessage (Num, null, content, pend, null) function is send. The details are as follows:

The main classes involved in SMS are smsmanager

The implementation of SMS mainly uses the smsmanager class, which inherits from Java Lang. object class. Let's introduce the main members of this class. Public method:

1、ArrayList<String> divideMessage(String text)

When the short message exceeds the maximum length of the SMS message, the short message is divided into several pieces. Parameter: Text -- initial message, cannot be null, return value: ordered ArrayList < string >, can be recombined into initial message

2、static SmsManager getDefault()

Gets the default instance of smsmanager. Return value: default instance of smsmanager

3、void SendDataMessage(String destinationAddress,String scAddress,short destinationPort,byte[] data,PendingIntent sentIntent,PendingIntent deliveryIntent)

Send an SMS based data to the specified application port. Parameters: 1). Destinationaddress -- the destination address of the message

2) . scaddress - the address or of the service center is empty, and the current default SMSC is used

3) Destinationport -- the destination port number of the message

4) , data -- the body of the message, that is, the data to be sent by the message

5) Sendintent -- if it is not empty, the pendingintent will be broadcast when the message is successfully sent or fails. The result code is activity RESULT_ OK indicates success, or result_ ERROR_ GENERIC_ FAILURE、RESULT_ ERROR_ RAdio_ OFF、RESULT_ ERROR_ NULL_ One of the PDUs indicates an error. Corresponding result_ ERROR_ GENERIC_ Failure, sendintent may include an additional "error code" containing a radio broadcast technology specific value, which is usually only useful when repairing faults. Each SMS based application controls the detection of sendintent. If sendintent is empty, the caller will detect all unknown applications, which will cause a small number of SMS to be sent at the time of detection.

6) Deliveryintent -- if it is not empty, the pendingintent will be broadcast when the message is successfully delivered to the receiver. Exception: if destinationaddress or data is null, an illegalargumentexception is thrown.

4、void sendMultipartTextMessage(String destinationAddress,ArrayList<String> parts,ArrayList<PendingIntent> sentIntents,ArrayList<PendingIntent> deliverIntents)

Send a multi part text based on SMS. The caller application has divided the message into the correct size by calling dividemessage (string text).

Parameters:

1) , destinationaddress -- the destination address of the message

2) . scaddress - the address or of the service center is empty, and the current default SMSC is used

3) , parts -- ordered ArrayList < string >, which can be recombined into initial messages

4) Sendintents -- the same as in the senddatamessage method, except that here is a group of pendingintents

5) Deliverintents -- the same as in the senddatamessage method, but here is a group of pendingintent exceptions: if the destinationaddress or data is empty, an illegalargumentexception exception will be thrown.

5、void sendTextMessage(String destinationAddress,String text,PendingIntent deliveryIntent)

Send an SMS based text. The meaning of the parameter is the same as the existing one before the exception, and will not be described again.

Constant:

First, call the system SMS interface to send SMS directly; The main codes are as follows:

Second: adjust the system to send SMS; The main codes are as follows:

The first method is mainly explained below. The first method can monitor the sending status and the receiving status of the other party. It is widely used.

The status codes returned by processing are as follows:

The following is the encapsulation of the above code

1. Sending SMS

2. Monitoring of SMS sending status

Test code:

Don't forget about permissions:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>