MmsMessageSenderpublic class MmsMessageSender extends Object implements MessageSender
Fields Summary |
---|
private static final String | TAG | private final android.content.Context | mContext | private final android.net.Uri | mMessageUri | private static final boolean | DEFAULT_DELIVERY_REPORT_MODE | private static final boolean | DEFAULT_READ_REPORT_MODE | private static final long | DEFAULT_EXPIRY_TIME | private static final int | DEFAULT_PRIORITY | private static final String | DEFAULT_MESSAGE_CLASS |
Constructors Summary |
---|
public MmsMessageSender(android.content.Context context, android.net.Uri location)
mContext = context;
mMessageUri = location;
if (mMessageUri == null) {
throw new IllegalArgumentException("Null message URI.");
}
|
Methods Summary |
---|
public boolean | sendMessage(long token)
// Load the MMS from the message uri
PduPersister p = PduPersister.getPduPersister(mContext);
GenericPdu pdu = p.load(mMessageUri);
if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ) {
throw new MmsException("Invalid message: " + pdu.getMessageType());
}
SendReq sendReq = (SendReq) pdu;
// Update headers.
updatePreferencesHeaders(sendReq);
// MessageClass.
sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes());
// Update the 'date' field of the message before sending it.
sendReq.setDate(System.currentTimeMillis() / 1000L);
p.updateHeaders(mMessageUri, sendReq);
// Move the message into MMS Outbox
p.move(mMessageUri, Mms.Outbox.CONTENT_URI);
// Start MMS transaction service
SendingProgressTokenManager.put(ContentUris.parseId(mMessageUri), token);
mContext.startService(new Intent(mContext, TransactionService.class));
return true;
| public static void | sendReadRec(android.content.Context context, java.lang.String to, java.lang.String messageId, int status)
EncodedStringValue[] sender = new EncodedStringValue[1];
sender[0] = new EncodedStringValue(to);
try {
final ReadRecInd readRec = new ReadRecInd(
new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()),
messageId.getBytes(),
PduHeaders.CURRENT_MMS_VERSION,
status,
sender);
readRec.setDate(System.currentTimeMillis() / 1000);
PduPersister.getPduPersister(context).persist(readRec, Mms.Outbox.CONTENT_URI);
context.startService(new Intent(context, TransactionService.class));
} catch (InvalidHeaderValueException e) {
Log.e(TAG, "Invalide header value", e);
} catch (MmsException e) {
Log.e(TAG, "Persist message failed", e);
}
| private void | updatePreferencesHeaders(com.google.android.mms.pdu.SendReq sendReq)
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
// Expiry.
sendReq.setExpiry(prefs.getLong(
MessagingPreferenceActivity.EXPIRY_TIME, DEFAULT_EXPIRY_TIME));
// Priority.
sendReq.setPriority(prefs.getInt(MessagingPreferenceActivity.PRIORITY, DEFAULT_PRIORITY));
// Delivery report.
boolean dr = prefs.getBoolean(MessagingPreferenceActivity.MMS_DELIVERY_REPORT_MODE,
DEFAULT_DELIVERY_REPORT_MODE);
sendReq.setDeliveryReport(dr?PduHeaders.VALUE_YES:PduHeaders.VALUE_NO);
// Read report.
boolean rr = prefs.getBoolean(MessagingPreferenceActivity.READ_REPORT_MODE,
DEFAULT_READ_REPORT_MODE);
sendReq.setReadReport(rr?PduHeaders.VALUE_YES:PduHeaders.VALUE_NO);
|
|