Search in sources :

Example 36 with MmsException

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);
        }
    }
}
Also used : Context(android.content.Context) MmsMessageSender(com.android.mms.transaction.MmsMessageSender) IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MmsException(com.google.android.mms.MmsException) MMSPart(com.google.android.mms.MMSPart)

Example 37 with MmsException

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;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 38 with MmsException

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;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 39 with MmsException

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;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

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