Search in sources :

Example 1 with MultimediaMessagePdu

use of com.google.android.mms.pdu_alt.MultimediaMessagePdu in project qksms by moezbhatti.

the class MessageUtils method getMultimediaMessageDetails.

private static String getMultimediaMessageDetails(Context context, Cursor cursor, int size) {
    int type = cursor.getInt(MessageColumns.COLUMN_MMS_MESSAGE_TYPE);
    if (type == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
        return getNotificationIndDetails(context, cursor);
    }
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();
    long id = cursor.getLong(MessageColumns.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    MultimediaMessagePdu msg;
    try {
        msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to load the message: " + uri, e);
        return context.getResources().getString(R.string.cannot_get_details);
    }
    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_message));
    if (msg instanceof RetrieveConf) {
        // From: ***
        String from = extractEncStr(context, ((RetrieveConf) msg).getFrom());
        details.append("\n\n");
        details.append(res.getString(R.string.from_label));
        details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));
    }
    // To: ***
    details.append("\n\n");
    details.append(res.getString(R.string.to_address_label));
    EncodedStringValue[] to = msg.getTo();
    if (to != null) {
        details.append(EncodedStringValue.concat(to));
    } else {
        Log.w(TAG, "recipient list is empty!");
    }
    // Bcc: ***
    if (msg instanceof SendReq) {
        EncodedStringValue[] values = ((SendReq) msg).getBcc();
        if ((values != null) && (values.length > 0)) {
            details.append("\n\n");
            details.append(res.getString(R.string.bcc_label));
            details.append(EncodedStringValue.concat(values));
        }
    }
    // Date: ***
    details.append("\n\n");
    int msgBox = cursor.getInt(MessageColumns.COLUMN_MMS_MESSAGE_BOX);
    if (msgBox == Mms.MESSAGE_BOX_DRAFTS) {
        details.append(res.getString(R.string.saved_label));
    } else if (msgBox == Mms.MESSAGE_BOX_INBOX) {
        details.append(res.getString(R.string.received_label));
    } else {
        details.append(res.getString(R.string.sent_label));
    }
    details.append(MessageUtils.formatTimeStampString(context, msg.getDate() * 1000L, true));
    // Subject: ***
    details.append("\n\n");
    details.append(res.getString(R.string.subject_label));
    EncodedStringValue subject = msg.getSubject();
    if (subject != null) {
        String subStr = subject.getString();
        // Message size should include size of subject.
        size += subStr.length();
        details.append(subStr);
    }
    // Priority: High/Normal/Low
    details.append("\n\n");
    details.append(res.getString(R.string.priority_label));
    details.append(getPriorityDescription(context, msg.getPriority()));
    // Message size: *** KB
    details.append("\n\n");
    details.append(res.getString(R.string.message_size_label));
    details.append((size - 1) / 1000 + 1);
    details.append(" KB");
    return details.toString();
}
Also used : MmsException(com.google.android.mms.MmsException) EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) MultimediaMessagePdu(com.google.android.mms.pdu_alt.MultimediaMessagePdu) Resources(android.content.res.Resources) Uri(android.net.Uri) SendReq(com.google.android.mms.pdu_alt.SendReq) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Example 2 with MultimediaMessagePdu

use of com.google.android.mms.pdu_alt.MultimediaMessagePdu in project qksms by moezbhatti.

the class SlideshowModel method getPduBody.

public static PduBody getPduBody(Context context, Uri msg) throws MmsException {
    PduPersister p = PduPersister.getPduPersister(context);
    GenericPdu pdu = p.load(msg);
    int msgType = pdu.getMessageType();
    if ((msgType == PduHeaders.MESSAGE_TYPE_SEND_REQ) || (msgType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF)) {
        return ((MultimediaMessagePdu) pdu).getBody();
    } else {
        throw new MmsException();
    }
}
Also used : MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) MultimediaMessagePdu(com.google.android.mms.pdu_alt.MultimediaMessagePdu)

Aggregations

MmsException (com.google.android.mms.MmsException)2 MultimediaMessagePdu (com.google.android.mms.pdu_alt.MultimediaMessagePdu)2 Resources (android.content.res.Resources)1 Uri (android.net.Uri)1 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)1 GenericPdu (com.google.android.mms.pdu_alt.GenericPdu)1 PduPersister (com.google.android.mms.pdu_alt.PduPersister)1 RetrieveConf (com.google.android.mms.pdu_alt.RetrieveConf)1 SendReq (com.google.android.mms.pdu_alt.SendReq)1