Tuesday, August 24, 2010

WinMobile - How to receive SMS

Windows Mobile, C#

Using MessageInterceptor object to receive SMS.
This is not able to read SMS already in the Inbox.


using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;

MessageInterceptor _interceptor = null;

private void Form_OnLoad(object sender, EventArgs e)
{
_interceptor = new MessageInterceptor();
_interceptor.MessageReceived += new MessageInterceptorEventHandler(Interceptor_MessageReceived);
}

void Interceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
SmsMessage msg = e.Message as SmsMessage;
if (msg != null)
{
System.Diagnostics.Debug.WriteLine("From: " + msg.From.Address);
System.Diagnostics.Debug.WriteLine("Body: " + msg.Body);
}
}

No comments: