RSS Feed for This PostCurrent Article

.NET: Detect Incoming Call or SMS in Windows Mobile Phone

Download Sample Code

I was looking for way to detect incoming call or SMS in Nokia Symbian phones and Windows Mobile Phone. It was not easy to do this in Symbian OS but to do it in .NET is very straightforward.

messageInterceptor = new MessageInterceptor();
messageInterceptor.InterceptionAction =
          InterceptionAction.NotifyAndDelete;
//messageInterceptor.MessageCondition.CaseSensitive = true;
//messageInterceptor.MessageCondition.Property =
//     MessageProperty.Sender;
messageInterceptor.MessageReceived +=
new MessageInterceptorEventHandler(Message_Received);

SystemState s;
s = new SystemState(SystemProperty.PhoneIncomingCall);
s.Changed += new ChangeEventHandler(PhoneEvents_Triggered);
stateList.Add(s);

s = new SystemState(SystemProperty.PhoneIncomingCallerName);
s.Changed += new ChangeEventHandler(PhoneEvents_Triggered);
stateList.Add(s);

s = new SystemState(SystemProperty.PhoneIncomingCallerNumber);
s.Changed += new ChangeEventHandler(PhoneEvents_Triggered);
stateList.Add(s);

s = new SystemState(SystemProperty.PhoneLastIncomingCallerContact);
s.Changed += new ChangeEventHandler(PhoneEvents_Triggered);
stateList.Add(s);

s = new SystemState(
         SystemProperty.PhoneIncomingCallerContactPropertyName);
s.Changed += new ChangeEventHandler(PhoneEvents_Triggered);
stateList.Add(s);

As you can see, I only need to use the MessageInterceptor class, and set the event handler to the method Message_Received.

void Message_Received(object sender, MessageInterceptorEventArgs e)
{
   if (e.Message is SmsMessage)
   {
           SmsMessage sms = (SmsMessage)e.Message;
           txtMsg.Text += sms.Body + "\r\n";
   } 

        txtMsg.Text += e.Message.From.Address.ToString()
         + "\n" + e.Message.From.Name.ToString() + "r\n";
}

And to do this in my Nokia N70 I have to use C++. It is not possible to use J2ME to achieve this yet.


Trackback URL


RSS Feed for This Post3 Comment(s)

  1. Avinash Shrimali | May 13, 2008 | Reply

    Good

  2. Eko | Aug 26, 2008 | Reply

    thx for your tutorial.but, do u have similar code write on VB?

  3. david | Dec 8, 2008 | Reply

    It is a great incredible program for me.I am doing a similar program,Could you send me a copy of code in c/c++??Thank you very much!!

RSS Feed for This PostPost a Comment