Search in sources :

Example 11 with MmsException

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

the class AudioModel method initModelFromUri.

private void initModelFromUri(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;
                boolean isFromMms = isMmsUri(uri);
                // our MMS database.
                if (isFromMms) {
                    path = c.getString(c.getColumnIndexOrThrow(Part._DATA));
                    mContentType = c.getString(c.getColumnIndexOrThrow(Part.CONTENT_TYPE));
                } else {
                    path = c.getString(c.getColumnIndexOrThrow(Audio.Media.DATA));
                    mContentType = c.getString(c.getColumnIndexOrThrow(Audio.Media.MIME_TYPE));
                    // Get more extras information which would be useful
                    // to the user.
                    String album = c.getString(c.getColumnIndexOrThrow("album"));
                    if (!TextUtils.isEmpty(album)) {
                        mExtras.put("album", album);
                    }
                    String artist = c.getString(c.getColumnIndexOrThrow("artist"));
                    if (!TextUtils.isEmpty(artist)) {
                        mExtras.put("artist", artist);
                    }
                }
                mSrc = path.substring(path.lastIndexOf('/') + 1);
                if (TextUtils.isEmpty(mContentType)) {
                    throw new MmsException("Type of media is unknown.");
                }
                if (LOCAL_LOGV) {
                    Log.v(TAG, "New AudioModel created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri + " mExtras=" + mExtras);
                }
            } else {
                throw new MmsException("Nothing found: " + uri);
            }
        } finally {
            c.close();
        }
    } else {
        throw new MmsException("Bad URI: " + uri);
    }
    initMediaDuration();
}
Also used : MmsException(com.google.android.mms.MmsException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 12 with MmsException

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

the class ImageModel method initModelFromUri.

private void initModelFromUri(Uri uri) throws MmsException {
    UriImage uriImage = new UriImage(mContext, uri);
    mContentType = uriImage.getContentType();
    if (TextUtils.isEmpty(mContentType)) {
        throw new MmsException("Type of media is unknown.");
    }
    mSrc = uriImage.getSrc();
    mWidth = uriImage.getWidth();
    mHeight = uriImage.getHeight();
    if (LOCAL_LOGV) {
        Log.v(TAG, "New ImageModel created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri);
    }
}
Also used : UriImage(com.moez.QKSMS.common.google.UriImage) MmsException(com.google.android.mms.MmsException)

Example 13 with MmsException

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

the class MediaModel method initMediaSize.

private void initMediaSize() throws MmsException {
    ContentResolver cr = mContext.getContentResolver();
    InputStream input = null;
    try {
        input = cr.openInputStream(mUri);
        if (input instanceof FileInputStream) {
            // avoid reading the whole stream to get its length
            FileInputStream f = (FileInputStream) input;
            mSize = (int) f.getChannel().size();
            if (isVideo() && mSize > MmsConfig.getMaxMessageSize()) {
                Log.w(TAG, "initMediaSize: Video size: f.getChannel().size(): " + mSize + " larger than max message size: " + MmsConfig.getMaxMessageSize());
            }
        } else if (input != null) {
            while (-1 != input.read()) {
                mSize++;
            }
        }
    } catch (IOException e) {
        // Ignore
        Log.e(TAG, "IOException caught while opening or reading stream", e);
        if (e instanceof FileNotFoundException) {
            throw new MmsException(e.getMessage());
        }
    } finally {
        if (null != input) {
            try {
                input.close();
            } catch (IOException e) {
                // Ignore
                Log.e(TAG, "IOException caught while closing stream", e);
            }
        }
    }
}
Also used : MmsException(com.google.android.mms.MmsException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContentResolver(android.content.ContentResolver)

Example 14 with MmsException

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

the class SmilHelper method getSmilDocument.

/**
     * Parse SMIL message and retrieve SMILDocument.
     *
     * @return A SMILDocument or null if parsing failed.
     */
private static SMILDocument getSmilDocument(PduPart smilPart) {
    try {
        byte[] data = smilPart.getData();
        if (data != null) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Parsing SMIL document.");
                Log.v(TAG, new String(data));
            }
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            SMILDocument document = new SmilXmlParser().parse(bais);
            return validate(document);
        }
    } catch (IOException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    } catch (SAXException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    }
    return null;
}
Also used : MmsException(com.google.android.mms.MmsException) SMILDocument(org.w3c.dom.smil.SMILDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SmilXmlParser(com.android.mms.dom.smil.parser.SmilXmlParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 15 with MmsException

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

the class PduPersister method persistPart.

public Uri persistPart(PduPart part, long msgId) throws MmsException {
    Uri uri = Uri.parse("content://mms/" + msgId + "/part");
    ContentValues values = new ContentValues(8);
    int charset = part.getCharset();
    if (charset != 0) {
        values.put(Part.CHARSET, charset);
    }
    String contentType = null;
    if (part.getContentType() != null) {
        contentType = toIsoString(part.getContentType());
        // Change it to "image/jpeg"
        if (ContentType.IMAGE_JPG.equals(contentType)) {
            contentType = ContentType.IMAGE_JPEG;
        }
        values.put(Part.CONTENT_TYPE, contentType);
        // To ensure the SMIL part is always the first part.
        if (ContentType.APP_SMIL.equals(contentType)) {
            values.put(Part.SEQ, -1);
        }
    } 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);
    }
    Uri res = SqliteWrapper.insert(mContext, mContentResolver, uri, values);
    if (res == null) {
        throw new MmsException("Failed to persist part, return null.");
    }
    persistData(part, res, contentType);
    // After successfully store the data, we should update
    // the dataUri of the part.
    part.setDataUri(res);
    return res;
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) Uri(android.net.Uri)

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