This doesn't work for me. I have the following:

[BroadcastReceiver(Enabled = true)]
    [IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })] 
    public class TextMessageListener : BroadcastReceiver
    {
        public static readonly string IntentAction =
"android.provider.Telephony.SMS_RECEIVED";

        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(context, "Msg received!",
ToastLength.Short).Show();
            if (intent.Action == IntentAction)
            {
                var bundle = intent.Extras;

                if (bundle != null)
                {
                    var pdus = bundle.Get ("pdus");
                    var castedPdus =
JNIEnv.GetArray<Java.Lang.Object>(pdus.Handle);

                    var bytes = new
Byte[JNIEnv.GetArrayLength(castedPdus[0].Handle)];
                    JNIEnv.CopyArray(castedPdus[0].Handle, bytes);
                    var message = Encoding.UTF8.GetString(bytes);
                    ((Main)context).ShowMessage(message);
                }
            }
        } 
    }

In the OnCreate() of my Main activity I'm registering the BroadcastReceiver
like this:

_receiver = new TextMessageListener();
            var intent = new IntentFilter();
            intent.AddAction(TextMessageListener.IntentAction);
            RegisterReceiver(_receiver, intent);

Receive Sms is added to the manifest as a permission. The problem is, that
the SMS_RECEIVED never seems to fire. I've had a breakpoint in the code, but
it never reaches it.



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Handle-incoming-SMS-tp5711524p5711623.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to