📚 Encyclopedia

Android · updated 2026-11-02

Sending MMS from an Android SMS app

androidmmspdusmscarrierapntelephony

An app that is the default SMS handler has to build and send MMS itself: compose a WAP binary PDU, write it to a file, and hand it to SmsManager.sendMultimediaMessage(). The hardest lesson from building the Message app (Kotlin, com.message.app) is that the carrier's MMSC can accept a message (HTTP 200, RESULT_OK) and then silently drop it. Success codes prove nothing about delivery; only a message actually arriving does.

The pipeline that works

UI -> repository.sendMms()
  -> store row in content://mms with MESSAGE_BOX_OUTBOX (not SENT)
  -> request the MMS network (keep the callback alive until the send is dispatched)
  -> build the PDU with PduComposer (pdu_alt)
  -> SmsManager.sendMultimediaMessage(context, pduUri, locationUrl, configBundle, sentIntent)
  -> local row PENDING
  -> MmsSentReceiver (registered in the manifest) -> SENT or FAILED

What went wrong, in order (each fix was needed, none alone was enough)

  1. PDU encoding bugs: wrong content-type byte (0xA3 vs 0xB3), missing SMIL part, missing null terminator in encoded strings.
  2. locationUrl was null: the MMSC URL was only in the config bundle; pass it directly as the locationUrl argument.
  3. No sent receiver: the sentIntent PendingIntent had no receiver, so there was zero error feedback.
  4. multipart/related without start=<smil> and type=application/smil parameters.
  5. MMS network released too early: requestNetwork callback unregistered immediately instead of after dispatch.
  6. The actual fix: a hand-rolled WAP binary encoder produced PDUs that passed the system parser and the MMSC's HTTP check but were discarded. Swapping to PduComposer from pdu_alt (AOSP-derived, Apache 2.0, from klinker41/android-smsmms, the same code QKSMS and Pulse use) fixed delivery. Never go back to hand-rolled PDU encoding.
  7. Status overwritten: writing MESSAGE_BOX_SENT to the provider before sending let the next sync overwrite the local PENDING status. Use OUTBOX until the sent callback.

Address formatting: the silent-drop trap

The AT&T MMSC accepted but dropped PDUs whose To header was display-formatted, e.g. (555) 123-4567; the same number sent bare (5551234567) round-tripped in the same second. The formatted value got in through a contact picker that wrote the raw formatted string to the system provider, and sync then copied it into the conversation's recipient list, poisoning every later MMS in that thread. Fix: normalize at the send boundary (PDU To and the provider addr table), and store normalized addresses so sync cannot re-poison. Only normalize things that look like phone numbers: email-to-MMS gateways and alphanumeric sender IDs ("AMZN") must pass through untouched, or distinct senders collapse into one thread.

Size limits

Carrier MMS caps at about 1 MB. A 1.9 MB GIF failed on device with resultCode=5. Budget media to about 900 KB on the server side and keep a hard 1 MB cap in the app. See GIF search behind a server proxy (Tenor shutdown, GIPHY, MMS size budgets).

Several images in one MMS share that one budget. Message (v2.35.0) lets the user pick up to 10 with PickMultipleVisualMedia and runs every picture through one shared preparer: each image gets its share of the budget as its compression target, and the whole batch is checked against the cap. Prepare off the main thread before creating the thread or sending anything; if the batch cannot fit, send to nobody and keep the attachments in the compose strip. When one message fans out to several recipients individually, prepare once and reuse the encoded parts.

APN fallback

System APN: content://telephony/carriers/preferapn (mmsc, mmsproxy, mmsport). Keep a fallback map keyed by MCC+MNC for when it is empty: AT&T 310410 (mmsc http://mmsc.mobile.att.net, proxy proxy.mobile.att.net:80), T-Mobile 310260, Verizon 311480, Metro 310120, Cricket 310150.

Diagnosing a send

  1. adb logcat -s MmsSender:* MmsSentReceiver:*: was it dispatched, what result code?
  2. UI state: PENDING (clock), SENT, FAILED.
  3. System says success but nobody receives it: PDU encoding or address problem, not APN.
  4. FAILED: APN, network, carrier.
  5. Try the stock messaging app on the same phone to separate app from device.
  6. Compare content://mms/{id}/addr rows of a known-good send against the failed one.

Gotchas

See also

Linked from

Sources: message memory (project_mms_debugging, project_bugs_fixed), Message app v2.3 to v2.10.1, message memory (v2.35.0), tldr post #1875