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