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


SMS Messaging Using the .NET Compact Framework : Page 4

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.

Registering the Application with the Device
Now that the application is capable of intercepting all relevant messages, there is one more thing left to do. The application itself may not be always running. For example, the device may be reset for some reason, and when it is rebooted the application would not be loaded unless the nurse launches it specifically. The device will not intercept incoming task messages unless the application is running.

A better method is to register the application with the device's registry so that whenever an incoming message is received (that satisfies the filtering rule), it automatically invokes the application (even when it has not yet been loaded).

To do this, declare an object of type Guid and assigns it a guid value:

    public partial class Form1 : Form
        const string HQPhoneNo = "651234567";
        MessageInterceptor msgInterceptor;
        Guid appID = new Guid("{283D3327-ADB8-41a0-B9DD-28E2845B5FF3}");

Author's Note: You can create a GUID for development use in Visual Studio 2008 by going to Tools→Create Guid.

In the Form1_Load event handler, use the static method IsApplicationLauncherEnabled() and check to see whether the application (identified using the appID object) is registered. If it is registered, load the existing MessageInterceptor class using the appID object. If it is not, proceed as normal and register the application using the EnableApplicationLauncher() method, shown in Listing 3.

Figure 5. Unregister: Adding a menu item control to unregister the application.

Because the application is automatically registered when it is loaded, it would be good to provide a means to unregister the application. To do so, add a menu item control to the Form (see Figure 5).

To unregister the application, use the DisableApplicationLauncher() method and remove the event handler for the MessageReceived event (as shown in Listing 4).

That's it! From now on, when the application is loaded for the first time, it is automatically registered with the device. Even if the application is unloaded from memory, it will automatically be invoked when an incoming message satisfying the filtering rule is received.

Increasingly Useful
This article has shown you how to send and receive SMS messages using the .NET Compact Framework. Using SMS messaging as a communication medium is gaining popularity as the cellular network gains in coverage and reliability. If you have ideas for using SMS messaging in your Windows Mobile applications, don't hesitate to share your ideas.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date