You have to create a broadcast receiver which does this.
I made a quick sample for you from some of the old threads on the
list. ChrisNTR was so kind to help someone else before with this and
made this gist: https://gist.github.com/cc8eec0c5b35fffc05cb
The full BroadcastReceiver can be seen below:
using System.Text;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Widget;
using Android.Telephony;
using Environment = System.Environment;
namespace MonoDroid.SMSFun
{
[BroadcastReceiver(Enabled = true, Label = "SMS Receiver")]
[IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })]
public class SMSBroadcastReceiver : BroadcastReceiver
{
private const string Tag = "SMSBroadcastReceiver";
private const string IntentAction =
"android.provider.Telephony.SMS_RECEIVED";
public override void OnReceive(Context context, Intent intent)
{
Log.Info(Tag, "Intent received: " + intent.Action);
if (intent.Action != IntentAction) return;
var bundle = intent.Extras;
if (bundle == null) return;
var pdus = bundle.Get("pdus");
var castedPdus = JNIEnv.GetArray<Java.Lang.Object>(pdus.Handle);
var msgs = new SmsMessage[castedPdus.Length];
var sb = new StringBuilder();
for (var i = 0; i < msgs.Length; i++)
{
var bytes = new
byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
msgs[i] = SmsMessage.CreateFromPdu(bytes);
sb.Append(string.Format("SMS From: {0}{1}Body:
{2}{1}", msgs[i].OriginatingAddress,
Environment.NewLine,
msgs[i].MessageBody));
}
Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
}
}
}
Remember to add the RECEIVE_SMS permission in your AndroidManifest:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
On Fri, Aug 24, 2012 at 9:21 AM, Александр <[email protected]> wrote:
> How can i handle and read incoming SMS message? On android.
>
>
>
> --
> View this message in context:
> http://mono-for-android.1047100.n5.nabble.com/Handle-incoming-SMS-tp5711524.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
--
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid