Search in sources :

Example 61 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 62 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 63 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 64 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)

Example 65 with MmsException

use of com.google.android.mms.MmsException in project XobotOS by xamarin.

the class PduPersister method updatePart.

private void updatePart(Uri uri, PduPart part) throws MmsException {
    ContentValues values = new ContentValues(7);
    int charset = part.getCharset();
    if (charset != 0) {
        values.put(Part.CHARSET, charset);
    }
    String contentType = null;
    if (part.getContentType() != null) {
        contentType = toIsoString(part.getContentType());
        values.put(Part.CONTENT_TYPE, 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(Part.FILENAME, fileName);
    }
    if (part.getName() != null) {
        String name = new String(part.getName());
        values.put(Part.NAME, name);
    }
    Object value = null;
    if (part.getContentDisposition() != null) {
        value = toIsoString(part.getContentDisposition());
        values.put(Part.CONTENT_DISPOSITION, (String) value);
    }
    if (part.getContentId() != null) {
        value = toIsoString(part.getContentId());
        values.put(Part.CONTENT_ID, (String) value);
    }
    if (part.getContentLocation() != null) {
        value = toIsoString(part.getContentLocation());
        values.put(Part.CONTENT_LOCATION, (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);
    }
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException)

Aggregations

MmsException (com.google.android.mms.MmsException)88 Uri (android.net.Uri)32 ContentValues (android.content.ContentValues)27 Cursor (android.database.Cursor)21 IOException (java.io.IOException)18 Intent (android.content.Intent)12 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)9 PduBody (com.google.android.mms.pdu.PduBody)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ContentResolver (android.content.ContentResolver)8 InputStream (java.io.InputStream)8 PduPersister (com.google.android.mms.pdu.PduPersister)7 PduPersister (com.google.android.mms.pdu_alt.PduPersister)7 Entry (java.util.Map.Entry)7 SpannableString (android.text.SpannableString)6 PduBody (com.google.android.mms.pdu_alt.PduBody)6 PduPart (com.google.android.mms.pdu_alt.PduPart)6 FileNotFoundException (java.io.FileNotFoundException)6 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)5 PduPart (com.google.android.mms.pdu.PduPart)5