Click here to Skip to main content
Click here to Skip to main content

Windows Mobile 5 Notifications

, 25 Feb 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
How to use Windows Mobile 5 Network Notifications to initiate data replication.


In this article, I describe how to use the Windows Mobile 5 State and Notification API (SNAPI) to get notified of changes in network states. Integrating network notification is the basis to implementing background data replication. Furthermore, when an application has knowledge of available networks, it can then choose the best connection to move data between the device and a back-end server.


The State and Notifications APIs provide a powerful built-in notification broker structure for the Windows Mobile 5.0 environment. Some of the requirements of SNAPI are:

  • .NET Compact Framework Version 2.0
  • Exposed via Microsoft.WindowsMobile.Status namespace
  • Specific to the Windows Mobile 5.0 platform
  • Included in the OS installation (not in the deployment CABs for the .NET CF 2.0) and Emulator

Using the Code

To implement application notifications, a reference to the following namespaces must be added:

  • Microsoft.WindowsMobile
  • Microsoft.WindowsMobile.Status

The following code outlines how to enable the notification callbacks within the application:

public void SetUpNotifications()
    // This tells which states to monitor
    SystemState s;
    // Monitor for ActiveSync Connection
    s = new SystemState(SystemProperty.CradlePresent);
    s.Changed += new ChangeEventHandler(ChangeOccurred);
    // Monitor for GPRS Connection
    s = new SystemState(SystemProperty.PhoneGprsCoverage);
    s.Changed += new ChangeEventHandler(ChangeOccurred);
    //Monitor for Network Connection (e.g. WiFi)
    s = new SystemState(SystemProperty.ConnectionsNetworkCount);
    s.Changed += new ChangeEventHandler(ChangeOccurred);


public void ChangeOccurred(object sender, ChangeEventArgs args)
    // If a change occurs
    SystemState state = (SystemState)sender;

public void UpdateConnectionState()
    // Set the check boxes based on the current state of the networks
    activesync.Checked = Convert.ToBoolean
    gprs.Checked = Convert.ToBoolean(SystemState.GetValue
    wifi.Checked = Convert.ToBoolean(SystemState.GetValue

Timers are a useful way of using the notification APIs to help determine when to initiate replication. On a specific interval, a function can be called to initiate data movement based on network availability. The following code shows how the current state of the network can help determine which data to retrieve.

private void Sync()
    // Initiate A Connection Using the preferred (available) network connection

    if (activesync.Checked)
        // Retrieve all data
    else if (wifi.Checked)
        // Retrieve medium priority data
    else if (gprs.Checked)
        // Retrieve high priority data
        txtStatus.Text = "No Connectivity.";


SNAPI is a excellent addition to a mobile application and can help to optimize data exchange. By adding a mobile database, an application can then be built to move data in the background to the point that users do not even realize synchronization is being executed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Liam Cavanagh

United States United States
Liam Cavanagh currently works as a Sr. Program Manager for Microsoft focusing new cloud services in the SQL Azure organization. Within this group, Liam has created a number of new services including SQL Azure Data Sync, Microsoft Codename "Data Transfer", and Eye on Earth leveraging the Windows Azure infrastucture.
Additionally, he works with enterprise corporations implementing enterprise cloud and mobile solutions and conducts training seminars worldwide.
Liam holds a Bachelor of Mathematics degree in Business and Information Systems from the University of Waterloo in Waterloo, Ontario, Canada.
Specialties: Windows Azure, SQL Azure, SQL Server, Cloud, Mobile, Replication and Database Synchronization Technologies
Liam Cavanagh is the founder of Cotega, a data notificaton and scheduling service for cloud databases. You can contact Liam at his cloud data blog.

Comments and Discussions

GeneralMy vote of 1 Pinmemberhfrmobile6-Sep-10 2:48 
GeneralSNAPI in native code PinmemberMember 38770655-Mar-08 3:19 
GeneralWindows Mobile 5 vs Windows CE 5 Pinmemberbrian2510-Aug-07 17:16 
AnswerRe: Windows Mobile 5 vs Windows CE 5 PinmemberLiam Cavanagh11-Aug-07 13:21 
GeneralRe: Windows Mobile 5 vs Windows CE 5 Pinmemberbrian2511-Aug-07 13:33 
Generalsyncronisation Pinmemberpmartike3-Jul-07 22:01 
AnswerRe: syncronisation PinmemberLiam Cavanagh4-Jul-07 3:59 
Generalconnection PinmemberMohammed.Reda8-Jun-07 7:42 
AnswerRe: connection PinmemberLiam Cavanagh8-Jun-07 8:19 
GeneralRe: connection PinmemberMohsen_Emgineer200411-Jun-07 14:47 
GeneralRe: connection PinmemberLiam Cavanagh12-Jun-07 4:58 
GeneralRe: connection PinmemberMohsen_Emgineer200412-Jun-07 17:31 
GeneralRe: connection PinmemberLiam Cavanagh13-Jun-07 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150302.1 | Last Updated 25 Feb 2008
Article Copyright 2007 by Liam Cavanagh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid