Java 类android.provider.Telephony.Mms.Part 实例源码

项目:darksms    文件:PduPersister.java   
public Uri persistPart(PduPart part, long msgId, HashMap<Uri, InputStream> preOpenedFiles)
        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 = getPartContentType(part);
    if (contentType != null) {
        // There is no "image/jpg" in Android (and it's an invalid mimetype).
        // 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, preOpenedFiles);
    // After successfully store the data, we should update
    // the dataUri of the part.
    part.setDataUri(res);

    return res;
}
项目:darksms    文件:PduPersister.java   
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(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);

    // Only update the data when:
    // 1. New binary data supplied or
    // 2. The Uri of the part is different from the current one.
    if ((part.getData() != null)
            || (uri != part.getDataUri())) {
        persistData(part, uri, contentType, preOpenedFiles);
    }
}
项目:qksms    文件:AudioModel.java   
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);

                // FIXME We suppose that there should be only two sources
                // of the audio, one is the media store, the other is
                // 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();
}
项目:qksms    文件:VideoModel.java   
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);
    }
}
项目:AndroidTextManager    文件:PduPersister.java   
public Uri persistPart(PduPart part, long msgId, HashMap<Uri, InputStream> preOpenedFiles)
        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 = getPartContentType(part);
    if (contentType != null) {
        // There is no "image/jpg" in Android (and it's an invalid mimetype).
        // 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 = mContentResolver.insert(uri, values);
    if (res == null) {
        throw new MmsException("Failed to persist part, return null.");
    }
    persistData(part, res, contentType, preOpenedFiles);
    // After successfully store the data, we should update
    // the dataUri of the part.
    part.setDataUri(res);
    return res;
}
项目:AndroidTextManager    文件:PduPersister.java   
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(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);
    }
    mContentResolver.update(uri, values, null, null);
    // Only update the data when:
    // 1. New binary data supplied or
    // 2. The Uri of the part is different from the current one.
    if ((part.getData() != null)
            || (uri != part.getDataUri())) {
        persistData(part, uri, contentType, preOpenedFiles);
    }
}
项目:sms_DualCard    文件:AudioModel.java   
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);

                // FIXME We suppose that there should be only two sources
                // of the audio, one is the media store, the other is
                // 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();
}
项目:android-aosp-mms    文件:AudioModel.java   
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);

                // FIXME We suppose that there should be only two sources
                // of the audio, one is the media store, the other is
                // 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();
}