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();
}
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);
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations