Colin Lightfoot
Colin Lightfoot

Reputation: 549

How to Detect Incoming MMS Messages on Android Devices using Xamarin.Forms?

I've looked at several questions on here and I'm sure I've made a mistake somewhere, but I cannot figure out why the Broadcast Receiver I made, MMSReceiver, is not notifying me that it received an MMS message via a toast or the information logs. What am I doing incorrectly?

Receiver class:

[BroadcastReceiver]
public class MMSReceiver : BroadcastReceiver
{
    private static readonly string TAG = "MMS Broadcast Receiver";

    public override void OnReceive(Context context, Intent intent)
    {
        Log.Info(TAG, "Intent received: " + intent.Action);
        Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
    }
}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.App">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="App.Android" android:theme="@style/MainTheme">

    <!-- https://stackoverflow.com/questions/11289568/monitoring-mms-received-like-sms-received-on-android -->
    <receiver android:name=".MMSReceiver">
        <intent-filter android:priority="1000"> IntentFilterPriority.HighPriority is equal to 1000 
            <action android:name="android.provider.Telephony.MMS_RECEIVED"/>
            <data android:mimeType="application/vnd.wap.mms-message" />
        </intent-filter>
    </receiver>
    
</application>
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <!-- Automatically starts at boot. -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <!-- Shows a pop-up window on top of all other applications, even if the app is not running in the foreground -->
</manifest>

Upvotes: 0

Views: 342

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 14981

For the Android4.4 version, Google offers SMS_DELIVER_ACTION (SMS) and WAP_PUSH_DELIVER_ACTION (MMS) intents for default SMS usage, meaning that only default SMS can receive these two broadcasts

Try to change the receiver in your Manifest.xml to :

<receiver android:name=".MMSReceiver">
    <intent-filter android:priority="1000">
        <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED"/>
        <data android:mimeType="application/vnd.wap.mms-message" />
    </intent-filter>
</receiver>

Upvotes: 1

Related Questions