Search in sources :

Example 21 with MmsException

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

the class MmsMessageSender method sendMessage.

public boolean sendMessage(long token) throws Throwable {
    // 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);
    sendReq.setMessageSize(mMessageSize);
    p.updateHeaders(mMessageUri, sendReq);
    long messageId = ContentUris.parseId(mMessageUri);
    // Move the message into MMS Outbox.
    if (!mMessageUri.toString().startsWith(Uri.parse("content://mms/drafts").toString())) {
        try {
            // If the message is already in the outbox (most likely because we created a "primed"
            // message in the outbox when the user hit send), then we have to manually put an
            // entry in the pending_msgs table which is where TransacationService looks for
            // messages to send. Normally, the entry in pending_msgs is created by the trigger:
            // insert_mms_pending_on_update, when a message is moved from drafts to the outbox.
            ContentValues values = new ContentValues(7);
            values.put(Telephony.MmsSms.PendingMessages.PROTO_TYPE, 1);
            values.put(Telephony.MmsSms.PendingMessages.MSG_ID, messageId);
            values.put(Telephony.MmsSms.PendingMessages.MSG_TYPE, pdu.getMessageType());
            values.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE, 0);
            values.put(Telephony.MmsSms.PendingMessages.ERROR_CODE, 0);
            values.put(Telephony.MmsSms.PendingMessages.RETRY_INDEX, 0);
            values.put(Telephony.MmsSms.PendingMessages.DUE_TIME, 0);
            SqliteWrapper.insert(mContext, mContext.getContentResolver(), Telephony.MmsSms.PendingMessages.CONTENT_URI, values);
        } catch (Throwable e) {
            p.move(mMessageUri, Telephony.Mms.Outbox.CONTENT_URI);
        }
    } else {
        p.move(mMessageUri, Telephony.Mms.Outbox.CONTENT_URI);
    }
    // Start MMS transaction service
    try {
        SendingProgressTokenManager.put(messageId, token);
        Intent service = new Intent(TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, mContext, TransactionService.class);
        mContext.startService(service);
    } catch (Exception e) {
        throw new Exception("transaction service not registered in manifest");
    }
    return true;
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) Intent(android.content.Intent) SendReq(com.google.android.mms.pdu_alt.SendReq) MmsException(com.google.android.mms.MmsException) InvalidHeaderValueException(com.google.android.mms.InvalidHeaderValueException)

Example 22 with MmsException

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

the class PduPersister method updatePart.

private void updatePart(Uri uri, PduPart part, HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {
    ContentValues values = new ContentValues(7);
    int charset = part.getCharset();
    if (charset != 0) {
        values.put("chset", charset);
    }
    String contentType = null;
    if (part.getContentType() != null) {
        contentType = toIsoString(part.getContentType());
        values.put("ct", contentType);
    } else {
        throw new MmsException("MIME type of the part must be set.");
    }
    if (part.getFilename() != null) {
        String fileName = new String(part.getFilename());
        values.put("fn", fileName);
    }
    if (part.getName() != null) {
        String name = new String(part.getName());
        values.put("name", name);
    }
    Object value = null;
    if (part.getContentDisposition() != null) {
        value = toIsoString(part.getContentDisposition());
        values.put("cd", (String) value);
    }
    if (part.getContentId() != null) {
        value = toIsoString(part.getContentId());
        values.put("cid", (String) value);
    }
    if (part.getContentLocation() != null) {
        value = toIsoString(part.getContentLocation());
        values.put("cl", (String) value);
    }
    SqliteWrapper.update(mContext, mContentResolver, uri, values, null, null);
    // 2. The Uri of the part is different from the current one.
    if ((part.getData() != null) || (uri != part.getDataUri())) {
        persistData(part, uri, contentType, preOpenedFiles);
    }
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException)

Example 23 with MmsException

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

the class RetryScheduler method markMmsFailedToSend.

private void markMmsFailedToSend(Context context, Uri msgUri) {
    try {
        PduPersister p = PduPersister.getPduPersister(context);
        // Move the message into MMS Outbox. A trigger will create an entry in
        // the "pending_msgs" table.
        p.move(msgUri, Telephony.Mms.Outbox.CONTENT_URI);
        // Now update the pending_msgs table with an error for that new item.
        ContentValues values = new ContentValues(1);
        values.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE, Telephony.MmsSms.ERR_TYPE_GENERIC_PERMANENT);
        long msgId = ContentUris.parseId(msgUri);
        SqliteWrapper.update(context, mContentResolver, Telephony.MmsSms.PendingMessages.CONTENT_URI, values, Telephony.MmsSms.PendingMessages.MSG_ID + "=" + msgId, null);
    } catch (MmsException e) {
        // Not much we can do here. If the p.move throws an exception, we'll just
        // leave the message in the draft box.
        Log.e(TAG, "Failed to move message to outbox and mark as error: " + msgUri, e);
    }
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister)

Example 24 with MmsException

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

the class MessageUtils method getNotificationIndDetails.

private static String getNotificationIndDetails(Context context, Cursor cursor) {
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();
    long id = cursor.getLong(MessageColumns.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    NotificationInd nInd;
    try {
        nInd = (NotificationInd) 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: Mms Notification.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_notification));
    // From: ***
    String from = extractEncStr(context, nInd.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));
    // Date: ***
    details.append("\n\n");
    details.append(res.getString(R.string.expire_on, MessageUtils.formatTimeStampString(context, nInd.getExpiry() * 1000L, true)));
    // Subject: ***
    details.append("\n\n");
    details.append(res.getString(R.string.subject_label));
    EncodedStringValue subject = nInd.getSubject();
    if (subject != null) {
        details.append(subject.getString());
    }
    // Message class: Personal/Advertisement/Infomational/Auto
    details.append("\n\n");
    details.append(res.getString(R.string.message_class_label));
    details.append(new String(nInd.getMessageClass()));
    // Message size: *** KB
    details.append("\n\n");
    details.append(res.getString(R.string.message_size_label));
    details.append(String.valueOf((nInd.getMessageSize() + 1023) / 1024));
    details.append(context.getString(R.string.kilobyte));
    return details.toString();
}
Also used : MmsException(com.google.android.mms.MmsException) EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) NotificationInd(com.google.android.mms.pdu_alt.NotificationInd) Resources(android.content.res.Resources) Uri(android.net.Uri)

Example 25 with MmsException

use of com.google.android.mms.MmsException 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)

Aggregations

MmsException (com.google.android.mms.MmsException)39 Uri (android.net.Uri)15 ContentValues (android.content.ContentValues)14 Cursor (android.database.Cursor)10 IOException (java.io.IOException)10 PduBody (com.google.android.mms.pdu_alt.PduBody)6 PduPart (com.google.android.mms.pdu_alt.PduPart)6 PduPersister (com.google.android.mms.pdu_alt.PduPersister)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Intent (android.content.Intent)5 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)5 InputStream (java.io.InputStream)4 ContentResolver (android.content.ContentResolver)3 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)3 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)3 SendReq (com.google.android.mms.pdu_alt.SendReq)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Resources (android.content.res.Resources)2