public class ShortMessage extends Object
Applications can obtain details about an SMS message by calling the methods of this instance.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
ShortMessage.ShortMessageClass |
Indicates the SMS type.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static Optional<ShortMessage> |
createMessage(byte[] pdu,
String specification) |
Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol.
|
ShortMessage.ShortMessageClass |
getMessageClass() |
Obtains the SMS type.
|
byte[] |
getPdu() |
Obtains Protocol Data Units (PDUs) from an SMS message.
|
int |
getProtocolId() |
Obtains the protocol identifier used for transmitting an SMS message.
|
String |
getScAddress() |
Obtains the short message service center (SMSC) address.
|
long |
getScTimestamp() |
Obtains the SMSC timestamp.
|
int |
getStatus() |
Obtains the SMS message status from the SMS-STATUS-REPORT message sent
by the Short Message Service Center (SMSC).
|
byte[] |
getUserRawData() |
Obtains the user data excluding the data header.
|
String |
getVisibleMessageBody() |
Obtains the SMS message body.
|
String |
getVisibleRawAddress() |
Obtains the address of the sender, which is to be displayed on the UI.
|
boolean |
hasReplyPath() |
Checks whether the received SMS contains "TP-Reply-Path".
|
boolean |
isReplaceMessage() |
Checks whether the received SMS is a "replace short message".
|
boolean |
isSmsStatusReportMessage() |
Checks whether the current message is SMS-STATUS-REPORT.
|
public int getProtocolId()
public ShortMessage.ShortMessageClass getMessageClass()
ShortMessageClass#UNKNOWN - unknown typeShortMessageClass#INSTANT_MESSAGE - instant messageShortMessageClass#OPTIONAL_MESSAGE - SMS message to be stored on the device or SIM cardShortMessageClass#SIM_MESSAGE - SMS message to be stored in the SIM cardShortMessageClass#FORWARD_MESSAGE - SMS message to be forwarded to another devicepublic static Optional<ShortMessage> createMessage(byte[] pdu, String specification)
After receiving the original PDU data, the system creates an SMS message instance according to the specified SMS protocol.
pdu - Indicates the original data, which is obtained from the received SMS.specification - Indicates the SMS protocol type. The value 3gpp indicates GSM/UMTS/LTE SMS,
and the value 3gpp2 indicates CDMA/LTE SMS.null if pdu is empty or specification
is not supported.public String getVisibleMessageBody()
null if the message body is invalid.public String getVisibleRawAddress()
null if the original address is invalid.public String getScAddress()
null if the address does not exist.public long getScTimestamp()
public byte[] getUserRawData()
public boolean isReplaceMessage()
true if the received SMS is a "replace short message"; returns false otherwise.public boolean hasReplyPath()
true if the received SMS contains "TP-Reply-Path"; returns false otherwise.public int getStatus()
0 if the SMS message was received.public byte[] getPdu()
public boolean isSmsStatusReportMessage()
true if the current message is SMS-STATUS-REPORT; returns false otherwise.