.NET: Detect Incoming Call or SMS in Windows Mobile Phone
By admin on Mar 3, 2008 in .NET, Programming
Related posts in this website for your search
Design Pattern in Java 101 - Visitor Pattern (Behavioral Pattern)
How to Receive SMS using .NET SMS Library
Design Pattern in Java 101 - Builder Pattern (Creational Pattern)
Design Pattern in .NET 101 - Decorator Pattern (Structural Pattern)
Free GPS Maps
Download Sample CodeI 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.