4

I am trying to receive an MMS message in my program. Here is what's in my manifest:

   <receiver android:name="com.webnation.text2email.receivers.MMSBroadcastReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />

            <data android:mimeType="application/vnd.wap.mms-message" />
        </intent-filter>
    </receiver>

However, when I receive an MMS message, my broadcast receiver is never called when stepping through it in the debugger. I'm running Android 7.0 on a Galaxy 7 (API 24). Did they put a stop to receiving MMS message programmatically?

Here is my broadcast receiver. This all used to work.

public class MMSBroadcastReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {

    this.context = context;
    String action = intent.getAction();
    String type = intent.getType();
    int typeMessage = -1;
    byte[] pushData;
    GenericPdu pdu = null;

    if (action.equals(ACTION_MMS_RECEIVED) && type.equals(MMS_DATA_TYPE)) {
        Bundle bundle = intent.getExtras();
        Timber.d("bundle " + bundle);
        if (bundle != null) {
            pushData = intent.getByteArrayExtra("data");
            PduParser parser = new PduParser(pushData);
            pdu = parser.parse();
            PduHeaders headers = pdu.getPduHeaders();

            Timber.d("buffer " + pushData);
            String incomingNumber = new String(pushData);
            int indx = incomingNumber.indexOf("/TYPE"); // not used, parse the number in MMUtils.getAddress instead
            if (indx > 0 && (indx - 15) > 0) {
                int newIndx = indx - 15;
                incomingNumber = incomingNumber.substring(newIndx, indx);
                char[] characters = incomingNumber.toCharArray();
                int index = 0;
                for (int i=0;i<characters.length;i++) {
                    if (Character.isDigit(characters[i]) ){


                        index = i;
                        break;
                    }
                }
                //indx = incomingNumber.indexOf("+");
                if (index > 0) {
                    incomingNumber = incomingNumber.substring(index);
                    TelephonyManager tm = (TelephonyManager)context.getSystemService(context.getApplicationContext().TELEPHONY_SERVICE);
                    String countryCode = tm.getNetworkCountryIso().toUpperCase();
                    try {
                        String prefix = CountryToPhonePrefix.prefixFor(countryCode).replace("+", "");
                        int indexOfBaseNumber = incomingNumber.indexOf(prefix);
                        if (indexOfBaseNumber > -1) {

                            if (indexOfBaseNumber == 0) {
                                int lengthPrefix = prefix.length();
                                indexOfBaseNumber = indexOfBaseNumber + lengthPrefix;
                            }
                            incomingNumber = incomingNumber.substring(indexOfBaseNumber);
                        }

                    } catch (IllegalArgumentException ie) {
                        Timber.e(ie);
                    } catch (IndexOutOfBoundsException ie) {
                        Timber.e(ie);;
                    }
                    Timber.d("Mobile Number: " + incomingNumber);
                }
            }

            int transactionId = bundle.getInt("transactionId", -1);
            Timber.d("transactionId " + transactionId);

            int pduType = bundle.getInt("pduType", -1);
            Timber.d("pduType " + pduType);

            byte[] buffer2 = bundle.getByteArray("header");

            if (buffer2 != null) {
                String header = new String(buffer2);
                Timber.d("header " + header);
            }
            List<MMSMessage> textMessages = MMSUtils.getMessagesFrom(context, intent); //meat of onReceive()
            sendMessages(textMessages);



        } else {
            Timber.e("Invalid PUSH data");
        }

    }


}
}

EDIT: after adding the RECEIVE_WAP_PUSH permission, the app started to work in the debugger, correctly receiving and processing MMS messages. However, the app is not processing MMS messages when in debug mode.

I tried using the android.provider.Telephony.WAP_PUSH_DELIVER action in my receiver and someone pointed out this was incorrect if not the default app.

not2qubit
  • 14,531
  • 8
  • 95
  • 135
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
  • 1
    Do you have the appropriate permissions? Have you requested runtime permission where applicable? From the docs, permissions are RECEIVE_MMS or RECEIVE_WAP_PUSH depending on type. – Gabe Sechan Feb 28 '18 at 21:54
  • `my broadcast receiver is never called` how do you know this? Maybe your very first `if` statement evaluated to `false`. Use a debugger and log messages. – Matt Clark Feb 28 '18 at 21:54
  • I know because I ran the debugger and set the break point to the first line of the onReceive. And this used to work. – Kristy Welsh Feb 28 '18 at 23:21
  • @GabeSechan - I think I didn't have the permission RECEIVE_WAP_PUSH. I added it and now it works. – Kristy Welsh Mar 01 '18 at 15:15
  • Take a look at the klinker library. https://github.com/klinker41/android-smsmms – Arya Mar 10 '18 at 05:40
  • After briefly working, this application is no longer working when not in debug mode. Break points are not being tripped when receiving MMS messages. – Kristy Welsh Apr 12 '18 at 19:30
  • 1
    have you requested `android.permission.RECEIVE_MMS` permission in your manifest? If so has the permission being granted? You can check it in Settings -> Apps -> your app -> Permission – Sagar Apr 14 '18 at 04:29
  • This is **not a duplicate**, because it refers to the API 24, which way different than KitKat API 19. We should probably add these labels to old posts to prevent excessive duplicate taggings. – not2qubit Oct 04 '18 at 17:06

0 Answers0