Filtering SMS Messages
So far the application intercepts all incoming messages, including those not sent by the system. However, from time to time a nurse might receive private messages from friends or family, that the application should not intercept.
You can set a message filter using the MessageCondition class. Modify the Form1_Load event to use the MessageCondition class to set up a filtering rule:
|Figure 4. Private Messages: Messages not intercepted are received by the device.|
private void Form1_Load(object sender, EventArgs e)
msgInterceptor = new MessageInterceptor(
//---set the filter for the message---
msgInterceptor.MessageReceived += new
From now on, only messages that start with the word "TSK_REQ" will be intercepted by the application; all other messages will be ignored and received by the device (see Figure 4
Also, the application may not be in the foreground all the time. For example, a nurse may make a phone call and thus switch the application to the background. When a new task message arrives, you should bring the application to the foreground programmatically.
First, import the following namespace:
In the event handler for the MessageReceived
event, append the following lines of code to bring the application to the foreground, shown in Listing 2
Basically, you first use reflection to find the path of the current application. You then use the Process.Start() method to run the application again. As Windows Mobile applications are single-instance, using the Start() method on an already running application simply brings it to the foreground.