public class SmsMessage extends Message
A SmsMessage consists of User Data (UD) and possibly may also contain a User Data Header (UDH). The User Data Header may be used for e.g. sending Multipart-Messages.
See the GSM 03.38 and GSM 03.40 specifications available at ETSI for further information.
Message
,
Serialized FormModifier and Type | Field and Description |
---|---|
static short |
CLASS_0
Message class 0
|
static short |
CLASS_1
Message class 1 (default, ME-specific)
|
static short |
CLASS_2
Message class 2 (SIM specific message)
|
static short |
CLASS_3
Message class 3 (Default meaning: TE-specific)
|
static short |
DC_8BIT
Data coding: 8bit data
|
static short |
DC_DEFAULT
Data coding: 7bit default GSM alphabet
|
static short |
DC_GROUP_DATA
Data Coding Group (default)
|
static short |
DC_GROUP_GENERAL
General Coding Group
|
static short |
DC_GROUP_MSG_WAITING_DISCARD
Message Waiting Indication Group: Discard Message
|
static short |
DC_GROUP_MSG_WAITING_STORE
Message Waiting Indication Group: Store Message
|
static short |
DC_UCS2
Data coding: Unicode (UCS2)
|
static short |
INDICATION_ACTIVE
Message Waiting Indication Active (default)
|
static short |
INDICATION_INACTIVE
Message Waiting Indication Inactive
|
static short |
INDICATION_TYPE_EMAIL
Message Waiting Indication Type: Electronic Mail Message Waiting
|
static short |
INDICATION_TYPE_FAX
Message Waiting Indication Type: Fax Message Waiting
|
static short |
INDICATION_TYPE_OTHER
Message Waiting Indication Type: Other Message Waiting (default)
|
static short |
INDICATION_TYPE_VOICEMAIL
Message Waiting Indication Type: Voicemail Message Waiting
|
static short |
NO_CLASS
Message class undefined (no class indication)
|
ACK_TIME, MT_BINARY, MT_STATUS, MT_TEXT, SENDER_TYPE_ALPHA, SENDER_TYPE_GUESS, SENDER_TYPE_NUMBER
Constructor and Description |
---|
SmsMessage()
Construct a new SmsMessage.
|
SmsMessage(SmsService service)
Deprecated.
since jSMS 1.7, use
SmsMessage() |
Modifier and Type | Method and Description |
---|---|
boolean |
containsUserDataHeader()
Test if the Message contains a User Data Header.
|
void |
copyFields(SmsMessage message)
Copy all public fields from a message.
|
short |
getAlphabet()
Returns the alphabet used for this message.
|
byte[] |
getBytes()
Get the message data.
|
short |
getCodingGroup()
Get the Coding Group for this Message.
|
java.util.Date |
getDeferredDeliveryAsDate()
Get the absolute deferred delivery date.
|
int |
getDeferredDeliveryInMinutes()
Return the deferred delivery date in minutes.
|
java.lang.String |
getID()
Returns the ID of this message.
|
short |
getIndicationState()
Get the Message Waiting Indication state.
|
short |
getIndicationType()
Get the Message Waiting Indication Type.
|
java.lang.String |
getMessage()
Get the Message (User Data) as String.
|
short |
getMessageClass()
Get the class of this message.
|
SmsMessage |
getParent()
Returns the parent (originating) message for this SMS.
|
short |
getPID()
Returns the protocol identifier (TP-PID) for this message.
|
java.lang.String |
getRecipient()
Get the recipient of this message.
|
Address |
getRecipientAddress()
Returns the recipient address or null if unset.
|
java.lang.String |
getSender()
Get the sender of this message.
|
Address |
getSenderAddress()
Returns the sender address or null if unset.
|
int |
getType()
Get the type of this message.
|
byte[] |
getUserData()
Get the User Data of this message.
|
byte[] |
getUserDataHeader()
Get the User Data Header for this message.
|
java.util.Date |
getValidityPeriodAsDate()
Get the absolute message validity period.
|
int |
getValidityPeriodInMinutes()
Return the Message validity period in minutes.
|
boolean |
hasDeferredDelivery()
Test if the Message has set a deferred delivery time.
|
boolean |
hasMessageClass()
Returns true if the Message has no Class associated, false otherwise.
|
boolean |
hasValidityPeriod()
Test if the Message contains a validity period
|
boolean |
isCompressed()
Test if the GSM compression flag is turned on
|
boolean |
isMMS()
Returns true if the More Messages to Send (MMS) flag ist set for this
message.
|
boolean |
isRejectDuplicates()
Returns true if duplicate short messages should be rejected by the SMSC,
false otherwise.
|
boolean |
isRelativeDeferredDelivery()
Test if the deferred delivery date is relative.
|
boolean |
isRelativeValidityPeriod()
Test if the Validity Period is relative.
|
boolean |
isReplyPath()
Returns the state of the reply path (TP-RP) bit field.
|
boolean |
requestStatusReport()
Test if a status report will be requested.
|
void |
requestStatusReport(boolean value)
Request a status report (notification).
|
void |
setAlphabet(short alpha)
Set the alphabet for this message.
|
void |
setCodingGroup(short group)
Set the Coding Group to use (see GSM 03.38).
|
void |
setCompression(boolean c)
Enable / disable the GSM Compression flag.
|
void |
setDeferredDelivery(java.util.Date deferredDelivery)
Set a deferred delivery date for this message.
|
void |
setDeferredDelivery(int minutes)
Set a deferred delivery date for this message.
|
void |
setIndicationState(short indication)
Set Message Waiting Indication state (active/inactive).
|
void |
setIndicationType(short type)
Set the Message Waiting Indication Type.
|
void |
setMessage(byte[] bytes)
Convenience method for setting the User Data.
|
void |
setMessage(java.lang.String msg)
Convenience method for setting the User Data.
|
void |
setMessageClass(short cls)
Set the class of this message.
|
void |
setMMS(boolean mms)
Set the More Messages to Send (MMS) flag.
|
void |
setParent(SmsMessage parent)
Used by
MultiPartMessage implementations to link this SMS
with the originating MultiPartMessage. |
void |
setPID(short pid)
Set the GSM TP-PID (Protocol Identifier) octet.
|
void |
setRecipient(java.lang.String recipient)
Set the recipient for this message.
|
void |
setRecipientAddress(Address addr)
Set/clear the recipient address of this message.
|
void |
setRejectDuplicates(boolean rd)
Instruct the SMSC to accept or reject a short message (SM) still held
in the SMSC which has the same message ID and the same destination
address as a previously submitted SM from the same OA.
|
void |
setReplyPath(boolean rp)
Set/Clear the reply path (TP-RP) bit field for this message.
|
void |
setSender(java.lang.String sender)
Set the sender of this message.
|
void |
setSenderAddress(Address addr)
Set/clear the sender of this message.
|
void |
setType(int type)
Set the type of message.
|
void |
setUserData(byte[] data)
Set or clear the User Data for this message.
|
void |
setUserDataHeader(boolean u)
Use this method for controlling the User Data Header Indication (UDHI).
|
void |
setUserDataHeader(byte[] header)
Set or clear the User Data Header (UDH).
|
void |
setValidityPeriod(java.util.Date validTill)
Set the absolute validity period for this message.
|
void |
setValidityPeriod(int minutes)
Set the relative validity period for this message.
|
java.lang.String |
toString()
Constructs a string representation of this Message
|
clone, getProperty, getSenderType, getTimestamp, setID, setProperty, setSenderType
public static final short NO_CLASS
public static final short CLASS_0
public static final short CLASS_1
public static final short CLASS_2
public static final short CLASS_3
public static final short DC_DEFAULT
public static final short DC_8BIT
public static final short DC_UCS2
public static final short DC_GROUP_GENERAL
public static final short DC_GROUP_DATA
public static final short DC_GROUP_MSG_WAITING_DISCARD
public static final short DC_GROUP_MSG_WAITING_STORE
public static final short INDICATION_ACTIVE
public static final short INDICATION_INACTIVE
public static final short INDICATION_TYPE_VOICEMAIL
public static final short INDICATION_TYPE_FAX
public static final short INDICATION_TYPE_EMAIL
public static final short INDICATION_TYPE_OTHER
public SmsMessage(SmsService service) throws java.lang.IllegalArgumentException
SmsMessage()
service
- the SmsService used to send this messagejava.lang.IllegalArgumentException
- if the service is nullpublic SmsMessage()
public void setMessageClass(short cls) throws java.lang.IllegalArgumentException
public short getMessageClass()
public boolean hasMessageClass()
setMessageClass(short)
public void setAlphabet(short alpha) throws java.lang.IllegalArgumentException
Notice
The alphabet allowed for sending the message depends
on the current coding group
:
If you specify Unicode Alphabet (DC_UCS2) and the current coding group
is set to DC_GROUP_DATA
, setAlphabet() will automatically set the coding group to DC_GROUP_GENERAL
since Unicode is not applicable for the DATA coding group.
If you try to use an alphabet not allowed for the message coding group, you may get unexpected results.
alpha
- the alphabet (DC_DEFAULT
,DC_8BIT
, DC_UCS2
)java.lang.IllegalArgumentException
- if an invalid alphabet has been specifiedsetCodingGroup(short)
public short getAlphabet()
DC_DEFAULT
,
DC_8BIT
,
DC_UCS2
public byte[] getUserDataHeader()
public void setUserDataHeader(byte[] header)
setUserDataHeader(boolean)
will
set set / cleared as well.
The header must be formatted according to the GSM 03.40 specification. It may contain 1-n header elements. The first octet of the array must contain the length of the header excluding the first octet (length of byte array minus one).
A Header element has the following structure:
FIELD | LENGTH |
---|---|
Information-Element-Identifier "A" | 1 octet |
Length of Information-Element "A" | 1 octet |
Information-Element "A" Data | 0 to "n" octets |
See the GSM 03.40 specification for more information about the UDH.
header
- the header data as byte array or null to clear the headerpublic byte[] getUserData()
public void setMessage(byte[] bytes)
DC_8BIT
.setMessage
in class Message
bytes
- the user data as byte arraysetUserData(byte[])
public int getType()
public void setMessage(java.lang.String msg)
DC_DEFAULT
.setMessage
in class Message
msg
- the message text.public java.lang.String getMessage()
getMessage
in class Message
getUserData()
public byte[] getBytes()
getUserData()
.getBytes
in class Message
getUserData()
public void setUserData(byte[] data)
data
- the user data as byte array or null to clear the user data.public void setCompression(boolean c)
Notice: This flag only has a meaning if you set the
Coding Group to DC_GROUP_GENERAL
.
setCodingGroup(short)
public boolean isCompressed()
public void setIndicationState(short indication) throws java.lang.IllegalArgumentException
DC_GROUP_MSG_WAITING_DISCARD
or DC_GROUP_MSG_WAITING_STORE
.indication
- the indication state (either INDICATION_ACTIVE
or
INDICATION_INACTIVE
)java.lang.IllegalArgumentException
setCodingGroup(short)
public short getIndicationState()
setIndicationState(short)
public void setIndicationType(short type) throws java.lang.IllegalArgumentException
DC_GROUP_MSG_WAITING_DISCARD
or DC_GROUP_MSG_WAITING_STORE
.type
- the indication type (INDICATION_TYPE_VOICEMAIL
,
INDICATION_TYPE_FAX
, INDICATION_TYPE_EMAIL
,
INDICATION_TYPE_OTHER
)java.lang.IllegalArgumentException
setCodingGroup(short)
public short getIndicationType()
setIndicationType(short)
public void setCodingGroup(short group)
group
- the Coding Grouppublic short getCodingGroup()
setCodingGroup(short)
public void setType(int type)
setType
in class Message
type
- the type of message (MT_TEXT or MT_BINARY)setAlphabet(short)
,
setMessageClass(short)
,
setUserDataHeader(boolean)
public void setUserDataHeader(boolean u)
setUserDataHeader(true)
ensures that the UDHI bit
is set when submitting the SMS.
Please note that the UDHI bit is automatically turned on when you pass
the User Data Header (UDH) using setUserDataHeader(byte[])
.
Therefore, it is only necessary to invoke this method when you pass both
UD and UDH using setUserData(byte[])
.
public boolean containsUserDataHeader()
public void setValidityPeriod(int minutes) throws java.lang.IllegalArgumentException
minutes
- message validity in minutes or 0 to clear the validity period.java.lang.IllegalArgumentException
- if a negative value has been specified.public void setValidityPeriod(java.util.Date validTill)
public boolean hasValidityPeriod()
public boolean isRelativeValidityPeriod()
public java.util.Date getValidityPeriodAsDate()
public int getValidityPeriodInMinutes()
public void setDeferredDelivery(int minutes) throws java.lang.IllegalArgumentException
SmsService.sendMessage(Message)
,
the SMSC will hold back the message until the given date has been reached.
Please note that SMS-Services not capable of setting a deferred delivery date will
silently ignore this setting.minutes
- the deferred delivery time in minutes relative to the
time when the message has been accepted by the SMSC.java.lang.IllegalArgumentException
- if minutes < 0.public void setDeferredDelivery(java.util.Date deferredDelivery)
SmsService.sendMessage(Message)
,
the SMSC will hold back the message until the given date has been reached.
Please note that SMS-Services not capable of setting a deferred delivery date will silently ignore this setting.
deferredDelivery
- the delivery date (absolute) or null to remove deferred delivery.public boolean hasDeferredDelivery()
public boolean isRelativeDeferredDelivery()
public java.util.Date getDeferredDeliveryAsDate()
public int getDeferredDeliveryInMinutes()
public void requestStatusReport(boolean value)
StatusReportMessage
public boolean requestStatusReport()
public void setPID(short pid) throws java.lang.IllegalArgumentException
pid
- the protocol identifier octetjava.lang.IllegalArgumentException
- if the specified value is lower than
0 or higher than 255.public short getPID()
setPID(short)
public void setRejectDuplicates(boolean rd)
public boolean isRejectDuplicates()
public void setReplyPath(boolean rp)
public boolean isReplyPath()
public void setMMS(boolean mms)
public boolean isMMS()
public void setParent(SmsMessage parent)
MultiPartMessage
implementations to link this SMS
with the originating MultiPartMessage.public SmsMessage getParent()
public java.lang.String toString()
Message
public void setSenderAddress(Address addr)
addr
- the sender address or null to clear the sender addresspublic void setRecipientAddress(Address addr)
addr
- the recipient addresspublic Address getSenderAddress()
public Address getRecipientAddress()
public void setSender(java.lang.String sender)
For fine-grained control over the sender address, consider
using setSenderAddress(Address)
with a GsmAddress
object.
public void setRecipient(java.lang.String recipient)
For fine-grained control over the recipient address, consider
using setRecipientAddress(Address)
with a GsmAddress
object.
setRecipient
in class Message
recipient
- address of the recipientpublic java.lang.String getSender()
getSender
in class Message
getSenderAddress()
public java.lang.String getRecipient()
getRecipient
in class Message
getRecipientAddress()
public void copyFields(SmsMessage message)
message
- the message to copy frompublic java.lang.String getID()
MultiPartMessage
objects,
the ID of the first part is returned.object XP, Inc. © 2000-2013. All rights reserved object XP