RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


SMS Messaging Using the .NET Compact Framework : Page 3

SMS messaging may have it's drawbacks, but it's benefits make it a viable solution for many of today's enteprise applications. This article uses a sample hospital application to show you how to integrate SMS messaging using the .NET Compact Framework.

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(
                InterceptionAction.NotifyAndDelete, true);

            //---set the filter for the message---
            msgInterceptor.MessageCondition =
                new MessageCondition(
                   "TSK_REQ", true);

            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:

using System.Reflection;
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.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date