Monday, 25 July 2011

MMS Listener

How to listen for Incoming MMS and Retrieve it's content? Here is the solution:

public class MmsListener extends BroadcastReceiver{

    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
            Bundle bundle = intent.getExtras();
                if (bundle != null){
                    //Retrieve MMS---
                    String type = intent.getType();
                        byte[] buffer = bundle.getByteArray("data");
                        String incomingNumber = new String(buffer);
                        int indx = incomingNumber.indexOf("/TYPE");
                        if(indx>0 && (indx-15)>0){
                            int newIndx = indx - 15;
                            incomingNumber = incomingNumber.substring(newIndx, indx);
                            indx = incomingNumber.indexOf("+");
                                incomingNumber = incomingNumber.substring(indx);
                                System.out.println("Mobile Number: " + incomingNumber);
            }catch(Exception e){
/                       Log.d("MMS data Exception caught", e.getMessage());


Note: In your manifest file add the BroadcastReceiver -

<receiver android:name=".listener.MmsListener">
        <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
        <data android:mimeType="application/vnd.wap.mms-message" />

<uses-permission android:name="android.permission.RECEIVE_MMS"/>


  1. Is it possible to grab the date, image, text from the intent as well?

  2. Nice, this works to grab the number, but how about the body of the mms (like the text or the image/audio/video)?