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


Build a 'SNAPI' App that Utilizes Windows Mobile 5.0 Managed APIs

The new Managed APIs in Windows Mobile 5.0 enable developers to do more, whether it's interacting with Pocket Outlook, working with the new telephony API, or sending and receiving SMSs. This article will help you get started using WM 5 with a great sample application that uses the State and Notification API to automatically sends an SMS message to callers when you are busy.

rior to Window Mobile 5.0 (WM5) even simple things such as checking battery status, sending an SMS, or programming Pocket Outlook were rather difficult. Fortunately, WM5 came with new managed APIs that expose a phenomenal number of abilities that will greatly enhance mobile applications.

Windows Mobile 5.0 offers many new APIs. Although they are spread across a number of different services, they are all focused on the common goal of improving developer productivity. In this article, I'll focus on the State and Notification API (SNAPI). Using SNAPI, I'll build a CallHandler application that automatically sends an SMS to a caller when the call recipient is busy and sets a Task reminder for the call recipient to return the call later.

The inspiration for this application is a new feature of some Nokia phones that ignores a call and sends a customized SMS to the caller (for example, to say that you'll call back later). The WM5 managed APIs make this kind of application development really simple. In the bargain you will get a useful application for yourself and at the same time learn features of the State and Notification API.

Don't Worry, Get SNAPI
Here's the official description of SNAPI from Microsoft.

The State and Notification Broker API provides a unified mechanism for storing device, application, and system-state information. Beyond simply being a unified store, it provides centralized notification architecture, allowing applications to easily register for notification, optionally starting an application in the event that a value of interest should change. The model allows applications to easily share their own state information as well. Windows Mobile 5.0 devices ship with well over 100 different state values available through the State and Notification Broker.
So what does this mean for you? Let's say you have a Windows Mobile application that is used for data collection. User-entered data must be backed up in this system when the battery level reaches, say, 15 percent. In order to do this you would need a way to check the current battery status—or better still to be notified when the battery level reaches 15 percent. Without WM5 this would be very difficult.

What You Need
Visual Studio.NET 2005
Windows Mobile 5.0 SDK for Pocket PC
Windows Mobile 5.0 SDK for SmartPhone

You need an actual Windows Mobile 5 phone device to test the code sample.

Or suppose you needed to respond to an incoming SMS message on a WM5 device, how would you do it? Prior to WM5 this was not possible using Managed code; the only option was to use P/Invoke. SNAPI makes all of this easy using managed code.

Before you can use SNAPI in your code you need to add references to two assemblies to your code: Microsoft.WindowsMobile and Microsoft.WindowsMobile.Status. This will enable you to access SNAPI and a lot of other useful WM5 APIs. The SystemState class gives you the ability to get the current value of a system state as well as a notification when that state changes. SNAPI provides access to 100+ pieces of state information. You need to figure out which particular state you need to monitor. The object browser (Figure 1) is the perfect way to parse through the wealth of state information provided via SNAPI. It makes sense to browse this list to get an overview of the various system properties that are exposed via SNAPI.

Figure 1. Use the object browser inside Visual Studio to browse all the various system properties that SNAPI can monitor.
For example, if you wanted to know the current battery state you would capture the value by typing:

This would get the remaining battery power level, expressed as a percentage of fully charged. Here I'm using the GetValue function of the SystemState class. It retrieves the value of a System Property using the property as a parameter.

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