Here are the examples of the java api class com.google.android.mms.pdu_alt.PduComposer taken from open source projects.
1. Transaction#getBytes()
Project: qksms
File: Transaction.java
File: Transaction.java
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) { } 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); 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; }