Search in sources :

Example 26 with MmsException

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

Example 27 with MmsException

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

Example 28 with MmsException

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

the class VideoModel method initFromContentUri.

private void initFromContentUri(Uri uri) throws MmsException {
    ContentResolver cr = mContext.getContentResolver();
    Cursor c = SqliteWrapper.query(mContext, cr, uri, null, null, null, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                String path;
                try {
                    // Local videos will have a data column
                    path = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA));
                } catch (IllegalArgumentException e) {
                    // For non-local videos, the path is the uri
                    path = uri.toString();
                }
                mSrc = path.substring(path.lastIndexOf('/') + 1);
                if (VideoModel.isMmsUri(uri)) {
                    mContentType = c.getString(c.getColumnIndexOrThrow(Part.CONTENT_TYPE));
                } else {
                    mContentType = c.getString(c.getColumnIndexOrThrow(Images.Media.MIME_TYPE));
                }
                if (TextUtils.isEmpty(mContentType)) {
                    throw new MmsException("Type of media is unknown.");
                }
                if (mContentType.equals(ContentType.VIDEO_MP4) && !(TextUtils.isEmpty(mSrc))) {
                    int index = mSrc.lastIndexOf(".");
                    if (index != -1) {
                        try {
                            String extension = mSrc.substring(index + 1);
                            if (!(TextUtils.isEmpty(extension)) && (extension.equalsIgnoreCase("3gp") || extension.equalsIgnoreCase("3gpp") || extension.equalsIgnoreCase("3g2"))) {
                                mContentType = ContentType.VIDEO_3GPP;
                            }
                        } catch (IndexOutOfBoundsException ex) {
                            if (LOCAL_LOGV) {
                                Log.v(TAG, "Media extension is unknown.");
                            }
                        }
                    }
                }
                if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                    Log.v(TAG, "New VideoModel initFromContentUri created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri);
                }
            } else {
                throw new MmsException("Nothing found: " + uri);
            }
        } finally {
            c.close();
        }
    } else {
        throw new MmsException("Bad URI: " + uri);
    }
}
Also used : MmsException(com.google.android.mms.MmsException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 29 with MmsException

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

the class AirplaneModeReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    // If we're going into airplane mode, no need to do anything
    if (intent.getBooleanExtra("state", true)) {
        return;
    }
    // Cursor to find the conversations that contain failed messages
    Cursor conversationCursor = context.getContentResolver().query(SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, Conversation.ALL_THREADS_PROJECTION, Conversation.FAILED_SELECTION, null, SmsHelper.sortDateDesc);
    // Loop through each of the conversations
    while (conversationCursor.moveToNext()) {
        Uri uri = ContentUris.withAppendedId(SmsHelper.MMS_SMS_CONTENT_PROVIDER, conversationCursor.getLong(Conversation.ID));
        // Find the failed messages within the conversation
        Cursor cursor = context.getContentResolver().query(uri, MessageColumns.PROJECTION, SmsHelper.FAILED_SELECTION, null, SmsHelper.sortDateAsc);
        // Map the cursor row to a MessageItem, then re-send it
        MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(cursor);
        while (cursor.moveToNext()) {
            try {
                MessageItem message = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
                sendSms(context, message);
            } catch (MmsException e) {
                e.printStackTrace();
            }
        }
        cursor.close();
    }
    conversationCursor.close();
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) MmsException(com.google.android.mms.MmsException) Cursor(android.database.Cursor) Uri(android.net.Uri) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns)

Example 30 with MmsException

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

the class SlideshowActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    // Play slide-show in full-screen mode.
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(icicle);
    mHandler = new Handler();
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(R.layout.view_slideshow);
    Intent intent = getIntent();
    Uri msg = intent.getData();
    final SlideshowModel model;
    try {
        model = SlideshowModel.createFromMessageUri(this, msg);
        mSlideCount = model.size();
    } catch (MmsException e) {
        Log.e(TAG, "Cannot present the slide show.", e);
        finish();
        return;
    }
    mSlideView = (SlideView) findViewById(R.id.slide_view);
    new SlideshowPresenter(this, mSlideView, model);
    mHandler.post(new Runnable() {

        private boolean isRotating() {
            return mSmilPlayer.isPausedState() || mSmilPlayer.isPlayingState() || mSmilPlayer.isPlayedState();
        }

        public void run() {
            mSmilPlayer = SmilPlayer.getPlayer();
            if (mSlideCount > 1) {
                // Only show the slideshow controller if we have more than a single slide.
                // Otherwise, when we play a sound on a single slide, it appears like
                // the slide controller should control the sound (seeking, ff'ing, etc).
                initMediaController();
                mSlideView.setMediaController(mMediaController);
            }
            // Use SmilHelper.getDocument() to ensure rebuilding the
            // entire SMIL document.
            mSmilDoc = SmilHelper.getDocument(model);
            if (isMMSConformance(mSmilDoc)) {
                int imageLeft = 0;
                int imageTop = 0;
                int textLeft = 0;
                int textTop = 0;
                LayoutModel layout = model.getLayout();
                if (layout != null) {
                    RegionModel imageRegion = layout.getImageRegion();
                    if (imageRegion != null) {
                        imageLeft = imageRegion.getLeft();
                        imageTop = imageRegion.getTop();
                    }
                    RegionModel textRegion = layout.getTextRegion();
                    if (textRegion != null) {
                        textLeft = textRegion.getLeft();
                        textTop = textRegion.getTop();
                    }
                }
                mSlideView.enableMMSConformanceMode(textLeft, textTop, imageLeft, imageTop);
            }
            if (DEBUG) {
                ByteArrayOutputStream ostream = new ByteArrayOutputStream();
                SmilXmlSerializer.serialize(mSmilDoc, ostream);
                if (LOCAL_LOGV) {
                    Log.v(TAG, ostream.toString());
                }
            }
            // Add event listener.
            ((EventTarget) mSmilDoc).addEventListener(SmilDocumentImpl.SMIL_DOCUMENT_END_EVENT, SlideshowActivity.this, false);
            mSmilPlayer.init(mSmilDoc);
            if (isRotating()) {
                mSmilPlayer.reload();
            } else {
                mSmilPlayer.play();
            }
        }
    });
}
Also used : MmsException(com.google.android.mms.MmsException) SlideshowModel(com.moez.QKSMS.model.SlideshowModel) Handler(android.os.Handler) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) RegionModel(com.moez.QKSMS.model.RegionModel) LayoutModel(com.moez.QKSMS.model.LayoutModel)

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