The filters are applied before your implementation of the TextMessageListener, which are specified in the [] brackets:
[BroadcastReceiver(Enabled = true)] [IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })] Therefore you should not need to register your listener in you activity like you do with this part of your code: _receiver = new TextMessageListener(); var intent = new IntentFilter(); intent.AddAction(TextMessageListener.IntentAction); RegisterReceiver(_receiver, intent); I don't think you can call a method in an activity from your BroadcastReceiver, so you have to do that in a different manner. This could be through a ContentProvider. On Wed, Aug 29, 2012 at 12:33 PM, sorniels <sorni...@fooz.dk> wrote: > 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 -- Med Venlig Hilsen / With Best Regards Tomasz Cielecki http://ostebaronen.dk _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid