SmsManagerpublic final class SmsManager extends Object Manages SMS operations such as sending data, text, and pdu SMS messages.
Get this object by calling the static method SmsManager.getDefault(). |
Fields Summary |
---|
private static SmsManager | sInstance | public static final int | STATUS_ON_SIM_FREEFree space (TS 51.011 10.5.3). | public static final int | STATUS_ON_SIM_READReceived and read (TS 51.011 10.5.3). | public static final int | STATUS_ON_SIM_UNREADReceived and unread (TS 51.011 10.5.3). | public static final int | STATUS_ON_SIM_SENTStored and sent (TS 51.011 10.5.3). | public static final int | STATUS_ON_SIM_UNSENTStored and unsent (TS 51.011 10.5.3). | public static final int | RESULT_ERROR_GENERIC_FAILUREGeneric failure cause | public static final int | RESULT_ERROR_RADIO_OFFFailed because radio was explicitly turned off | public static final int | RESULT_ERROR_NULL_PDUFailed because no pdu provided | public static final int | RESULT_ERROR_NO_SERVICEFailed because service is currently unavailable |
Constructors Summary |
---|
private SmsManager()
// nothing to see here
|
Methods Summary |
---|
public boolean | copyMessageToSim(byte[] smsc, byte[] pdu, int status)Copy a raw SMS PDU to the SIM.
boolean success = false;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.copyMessageToSimEf(status, pdu, smsc);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
| private java.util.ArrayList | createMessageListFromRawRecords(java.util.List records)Create a list of SmsMessage s from a list of RawSmsData
records returned by getAllMessagesFromSim()
ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
if (records != null) {
int count = records.size();
for (int i = 0; i < count; i++) {
SmsRawData data = (SmsRawData)records.get(i);
// List contains all records, including "free" records (null)
if (data != null) {
SmsMessage sms =
SmsMessage.createFromEfRecord(i+1, data.getBytes());
messages.add(sms);
}
}
}
return messages;
| public boolean | deleteMessageFromSim(int messageIndex)Delete the specified message from the SIM.
boolean success = false;
byte[] pdu = new byte[SimConstants.SMS_RECORD_LENGTH-1];
Arrays.fill(pdu, (byte)0xff);
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.updateMessageOnSimEf(messageIndex,
STATUS_ON_SIM_FREE, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
| public java.util.ArrayList | divideMessage(java.lang.String text)Divide a text message into several messages, none bigger than
the maximum SMS message size.
int size = text.length();
int[] params = SmsMessage.calculateLength(text, false);
/* SmsMessage.calculateLength returns an int[4] with:
* int[0] being the number of SMS's required,
* int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int messageCount = params[0];
int encodingType = params[3];
ArrayList<String> result = new ArrayList<String>(messageCount);
int start = 0;
int limit;
if (messageCount > 1) {
limit = (encodingType == SmsMessage.ENCODING_7BIT) ?
SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER :
SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER;
} else {
limit = (encodingType == SmsMessage.ENCODING_7BIT) ?
SmsMessage.MAX_USER_DATA_SEPTETS : SmsMessage.MAX_USER_DATA_BYTES;
}
try {
while (start < size) {
int end = GsmAlphabet.findLimitIndex(text, start, limit, encodingType);
result.add(text.substring(start, end));
start = end;
}
} catch (EncodeException e) {
// ignore it.
}
return result;
| public java.util.ArrayList | getAllMessagesFromSim()Retrieves all messages currently stored on SIM.
List<SmsRawData> records = null;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
records = simISms.getAllMessagesFromSimEf();
}
} catch (RemoteException ex) {
// ignore it
}
return createMessageListFromRawRecords(records);
| public static android.telephony.gsm.SmsManager | getDefault()Get the default instance of the SmsManager
if (sInstance == null) {
sInstance = new SmsManager();
}
return sInstance;
| public void | sendDataMessage(java.lang.String destinationAddress, java.lang.String scAddress, short destinationPort, byte[] data, android.app.PendingIntent sentIntent, android.app.PendingIntent deliveryIntent)Send a data based SMS to a specific application port.
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (data == null || data.length == 0) {
throw new IllegalArgumentException("Invalid message data");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress,
destinationPort, data, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
| public void | sendMultipartTextMessage(java.lang.String destinationAddress, java.lang.String scAddress, java.util.ArrayList parts, java.util.ArrayList sentIntents, java.util.ArrayList deliveryIntents)Send a multi-part text based SMS. The callee should have already
divided the message into correctly sized parts by calling
divideMessage .
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (parts == null || parts.size() < 1) {
throw new IllegalArgumentException("Invalid message body");
}
if (parts.size() > 1) {
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
simISms.sendMultipartText(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
} catch (RemoteException ex) {
// ignore it
}
} else {
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
if (sentIntents != null && sentIntents.size() > 0) {
sentIntent = sentIntents.get(0);
}
if (deliveryIntents != null && deliveryIntents.size() > 0) {
deliveryIntent = deliveryIntents.get(0);
}
sendTextMessage(destinationAddress, scAddress, parts.get(0),
sentIntent, deliveryIntent);
}
| private void | sendRawPdu(byte[] smsc, byte[] pdu, android.app.PendingIntent sentIntent, android.app.PendingIntent deliveryIntent)Send a raw SMS PDU.
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
simISms.sendRawPdu(smsc, pdu, sentIntent, deliveryIntent);
}
} catch (RemoteException ex) {
// ignore it
}
| public void | sendTextMessage(java.lang.String destinationAddress, java.lang.String scAddress, java.lang.String text, android.app.PendingIntent sentIntent, android.app.PendingIntent deliveryIntent)Send a text based SMS.
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(
scAddress, destinationAddress, text, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
| public boolean | updateMessageOnSim(int messageIndex, int newStatus, byte[] pdu)Update the specified message on the SIM.
boolean success = false;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.updateMessageOnSimEf(messageIndex, newStatus, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
|
|