use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class Transaction method sendMmsMessage.
private void sendMmsMessage(String text, String[] addresses, Bitmap[] image, String[] imageNames, byte[] media, String mimeType, String subject) {
// merge the string[] of addresses into a single string so they can be inserted into the database easier
String address = "";
for (int i = 0; i < addresses.length; i++) {
address += addresses[i] + " ";
}
address = address.trim();
// create the parts to send
ArrayList<MMSPart> data = new ArrayList<>();
for (int i = 0; i < image.length; i++) {
// turn bitmap into byte array to be stored
byte[] imageBytes = Message.bitmapToByteArray(image[i]);
MMSPart part = new MMSPart();
part.MimeType = "image/jpeg";
part.Name = (imageNames != null) ? imageNames[i] : ("image" + i);
part.Data = imageBytes;
data.add(part);
}
// eg. videos, audio, contact cards, location maybe?
if (media.length > 0 && mimeType != null) {
MMSPart part = new MMSPart();
part.MimeType = mimeType;
part.Name = mimeType.split("/")[0];
part.Data = media;
data.add(part);
}
if (!text.equals("")) {
// add text to the end of the part and send
MMSPart part = new MMSPart();
part.Name = "text";
part.MimeType = "text/plain";
part.Data = text.getBytes();
data.add(part);
}
MessageInfo info;
try {
info = getBytes(context, saveMessage, address.split(" "), data.toArray(new MMSPart[data.size()]), subject);
} catch (MmsException e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
try {
MmsMessageSender sender = new MmsMessageSender(context, info.location, info.bytes.length);
sender.sendMessage(info.token);
IntentFilter filter = new IntentFilter();
filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int progress = intent.getIntExtra("progress", -3);
if (LOCAL_LOGV)
Log.v(TAG, "progress: " + progress);
// send progress broadcast to update ui if desired...
Intent progressIntent = new Intent(MMS_PROGRESS);
progressIntent.putExtra("progress", progress);
context.sendBroadcast(progressIntent);
if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) {
context.sendBroadcast(new Intent(REFRESH));
try {
context.unregisterReceiver(this);
} catch (Exception e) {
// TODO fix me
// receiver is not registered force close error... hmm.
}
} else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) {
// This seems to get called only after the progress has reached 100 and then something else goes wrong, so here we will try and send again and see if it works
if (LOCAL_LOGV)
Log.v(TAG, "sending aborted for some reason...");
}
}
};
context.registerReceiver(receiver, filter);
} catch (Throwable e) {
Log.e(TAG, "exception thrown", e);
// insert the pdu into the database and return the bytes to send
if (settings.getWifiMmsFix()) {
sendMMS(info.bytes);
} else {
sendMMSWiFi(info.bytes);
}
}
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class MessageUtils method saveRingtone.
/**
* Copies media from an Mms to the DrmProvider
*
* @param context
* @param msgId
*/
public static boolean saveRingtone(Context context, long msgId) {
boolean result = true;
PduBody body = null;
try {
body = SlideshowModel.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
} catch (MmsException e) {
Log.e(TAG, "copyToDrmProvider can't load pdu body: " + msgId);
}
if (body == null) {
return false;
}
int partNum = body.getPartsNum();
for (int i = 0; i < partNum; i++) {
PduPart part = body.getPart(i);
String type = new String(part.getContentType());
if (DrmUtils.isDrmType(type)) {
// All parts (but there's probably only a single one) have to be successful
// for a valid result.
result &= copyPart(context, part, Long.toHexString(msgId));
}
}
return result;
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class MessageUtils method copyMedia.
/**
* Copies media from an Mms to the "download" directory on the SD card. If any of the parts
* are audio types, drm'd or not, they're copied to the "Ringtones" directory.
*
* @param context
* @param msgId
*/
public static boolean copyMedia(Context context, long msgId) {
boolean result = true;
PduBody body = null;
try {
body = SlideshowModel.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
} catch (MmsException e) {
Log.e(TAG, "copyMedia can't load pdu body: " + msgId);
}
if (body == null) {
return false;
}
int partNum = body.getPartsNum();
for (int i = 0; i < partNum; i++) {
PduPart part = body.getPart(i);
// all parts have to be successful for a valid result.
result &= copyPart(context, part, Long.toHexString(msgId));
}
return result;
}
use of com.google.android.mms.MmsException in project qksms by moezbhatti.
the class MessageUtils method isForwardable.
/**
* Returns true if all drm'd parts are forwardable.
*
* @param context
* @param msgId
* @return true if all drm'd parts are forwardable.
*/
public static boolean isForwardable(Context context, long msgId) {
PduBody body = null;
try {
body = SlideshowModel.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
} catch (MmsException e) {
Log.e(TAG, "getDrmMimeType can't load pdu body: " + msgId);
}
if (body == null) {
return false;
}
int partNum = body.getPartsNum();
for (int i = 0; i < partNum; i++) {
PduPart part = body.getPart(i);
String type = new String(part.getContentType());
if (DrmUtils.isDrmType(type) && !DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.TRANSFER)) {
return false;
}
}
return true;
}
Aggregations