Search in sources :

Example 6 with EncodedStringValue

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

the class RetrieveTransaction method sendAcknowledgeInd.

private void sendAcknowledgeInd(RetrieveConf rc) throws MmsException, IOException {
    // Send M-Acknowledge.ind to MMSC if required.
    // If the Transaction-ID isn't set in the M-Retrieve.conf, it means
    // the MMS proxy-relay doesn't require an ACK.
    byte[] tranId = rc.getTransactionId();
    if (tranId != null) {
        // Create M-Acknowledge.ind
        AcknowledgeInd acknowledgeInd = new AcknowledgeInd(PduHeaders.CURRENT_MMS_VERSION, tranId);
        // insert the 'from' address per spec
        String lineNumber = Utils.getMyPhoneNumber(mContext);
        acknowledgeInd.setFrom(new EncodedStringValue(lineNumber));
        // Pack M-Acknowledge.ind and send it
        if (MmsConfig.getNotifyWapMMSC()) {
            sendPdu(new PduComposer(mContext, acknowledgeInd).make(), mContentLocation);
        } else {
            sendPdu(new PduComposer(mContext, acknowledgeInd).make());
        }
    }
}
Also used : EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) AcknowledgeInd(com.google.android.mms.pdu_alt.AcknowledgeInd) PduComposer(com.google.android.mms.pdu_alt.PduComposer)

Example 7 with EncodedStringValue

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

the class DownloadManager method getMessage.

private String getMessage(Uri uri) throws MmsException {
    NotificationInd ind = (NotificationInd) PduPersister.getPduPersister(mContext).load(uri);
    EncodedStringValue v = ind.getSubject();
    String subject = (v != null) ? v.getString() : mContext.getString(R.string.no_subject);
    // TODO: Actually get the sender, or at least the phone number here
    String from = mContext.getString(R.string.unknown_sender);
    return mContext.getString(R.string.dl_failure_notification, subject, from);
}
Also used : EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) NotificationInd(com.google.android.mms.pdu_alt.NotificationInd)

Example 8 with EncodedStringValue

use of com.google.android.mms.pdu_alt.EncodedStringValue 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 9 with EncodedStringValue

use of com.google.android.mms.pdu_alt.EncodedStringValue 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 10 with EncodedStringValue

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

the class Transaction method getBytes.

public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts, String subject) throws MmsException {
    final SendReq sendRequest = new SendReq();
    // create send request addresses
    for (int i = 0; i < recipients.length; i++) {
        final EncodedStringValue[] phoneNumbers = EncodedStringValue.extract(recipients[i]);
        if (phoneNumbers != null && phoneNumbers.length > 0) {
            sendRequest.addTo(phoneNumbers[0]);
        }
    }
    if (subject != null) {
        sendRequest.setSubject(new EncodedStringValue(subject));
    }
    sendRequest.setDate(Calendar.getInstance().getTimeInMillis() / 1000L);
    try {
        sendRequest.setFrom(new EncodedStringValue(Utils.getMyPhoneNumber(context)));
    } catch (Exception e) {
    // my number is nothing
    }
    final PduBody pduBody = new PduBody();
    // assign parts to the pdu body which contains sending data
    if (parts != null) {
        for (int i = 0; i < parts.length; i++) {
            MMSPart part = parts[i];
            if (part != null) {
                try {
                    PduPart partPdu = new PduPart();
                    partPdu.setName(part.Name.getBytes());
                    partPdu.setContentType(part.MimeType.getBytes());
                    if (part.MimeType.startsWith("text")) {
                        partPdu.setCharset(CharacterSets.UTF_8);
                    }
                    partPdu.setData(part.Data);
                    pduBody.addPart(partPdu);
                } catch (Exception e) {
                }
            }
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmilXmlSerializer.serialize(SmilHelper.createSmilDocument(pduBody), out);
    PduPart smilPart = new PduPart();
    smilPart.setContentId("smil".getBytes());
    smilPart.setContentLocation("smil.xml".getBytes());
    smilPart.setContentType(ContentType.APP_SMIL.getBytes());
    smilPart.setData(out.toByteArray());
    pduBody.addPart(0, smilPart);
    sendRequest.setBody(pduBody);
    // create byte array which will actually be sent
    final PduComposer composer = new PduComposer(context, sendRequest);
    final byte[] bytesToSend;
    try {
        bytesToSend = composer.make();
    } catch (OutOfMemoryError e) {
        throw new MmsException("Out of memory!");
    }
    MessageInfo info = new MessageInfo();
    info.bytes = bytesToSend;
    if (saveMessage) {
        try {
            PduPersister persister = PduPersister.getPduPersister(context);
            info.location = persister.persist(sendRequest, Uri.parse("content://mms/outbox"), true, settings.getGroup(), null);
        } catch (Exception e) {
            if (LOCAL_LOGV)
                Log.v(TAG, "error saving mms message");
            Log.e(TAG, "exception thrown", e);
            // use the old way if something goes wrong with the persister
            insert(context, recipients, parts, subject);
        }
    }
    try {
        Cursor query = context.getContentResolver().query(info.location, new String[] { "thread_id" }, null, null, null);
        if (query != null && query.moveToFirst()) {
            info.token = query.getLong(query.getColumnIndex("thread_id"));
        } else {
            // just default sending token for what I had before
            info.token = 4444L;
        }
    } catch (Exception e) {
        Log.e(TAG, "exception thrown", e);
        info.token = 4444L;
    }
    return info;
}
Also used : EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPersister(com.google.android.mms.pdu_alt.PduPersister) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Cursor(android.database.Cursor) SendReq(com.google.android.mms.pdu_alt.SendReq) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PduComposer(com.google.android.mms.pdu_alt.PduComposer) MmsException(com.google.android.mms.MmsException) PduPart(com.google.android.mms.pdu_alt.PduPart) MMSPart(com.google.android.mms.MMSPart)

Aggregations

EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)10 Uri (android.net.Uri)5 MmsException (com.google.android.mms.MmsException)5 PduComposer (com.google.android.mms.pdu_alt.PduComposer)4 PduPersister (com.google.android.mms.pdu_alt.PduPersister)3 SendReq (com.google.android.mms.pdu_alt.SendReq)3 Resources (android.content.res.Resources)2 Cursor (android.database.Cursor)2 NotificationInd (com.google.android.mms.pdu_alt.NotificationInd)2 ReadRecInd (com.google.android.mms.pdu_alt.ReadRecInd)2 IOException (java.io.IOException)2 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 RateController (com.android.mms.util.RateController)1 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)1 MMSPart (com.google.android.mms.MMSPart)1 AcknowledgeInd (com.google.android.mms.pdu_alt.AcknowledgeInd)1 MultimediaMessagePdu (com.google.android.mms.pdu_alt.MultimediaMessagePdu)1 PduBody (com.google.android.mms.pdu_alt.PduBody)1 PduParser (com.google.android.mms.pdu_alt.PduParser)1