Click here to Skip to main content
13,549,174 members
Click here to Skip to main content
Add your own
alternative version


65 bookmarked
Posted 16 Apr 2007
Licenced CPOL

Windows Mobile 5 Notifications

, 25 Feb 2008
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.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
hfrmobile6-Sep-10 1:48
memberhfrmobile6-Sep-10 1:48 
GeneralSNAPI in native code Pin
Member 38770655-Mar-08 2:19
memberMember 38770655-Mar-08 2:19 
GeneralWindows Mobile 5 vs Windows CE 5 Pin
brian2510-Aug-07 16:16
memberbrian2510-Aug-07 16:16 
AnswerRe: Windows Mobile 5 vs Windows CE 5 Pin
Liam Cavanagh11-Aug-07 12:21
memberLiam Cavanagh11-Aug-07 12:21 
GeneralRe: Windows Mobile 5 vs Windows CE 5 Pin
brian2511-Aug-07 12:33
memberbrian2511-Aug-07 12:33 
Generalsyncronisation Pin
pmartike3-Jul-07 21:01
memberpmartike3-Jul-07 21:01 
AnswerRe: syncronisation Pin
Liam Cavanagh4-Jul-07 2:59
memberLiam Cavanagh4-Jul-07 2:59 
Generalconnection Pin
Mohammed.Reda8-Jun-07 6:42
memberMohammed.Reda8-Jun-07 6:42 
AnswerRe: connection Pin
Liam Cavanagh8-Jun-07 7:19
memberLiam Cavanagh8-Jun-07 7:19 
GeneralRe: connection Pin
Mohsen_Emgineer200411-Jun-07 13:47
memberMohsen_Emgineer200411-Jun-07 13:47 
GeneralRe: connection Pin
Liam Cavanagh12-Jun-07 3:58
memberLiam Cavanagh12-Jun-07 3:58 
GeneralRe: connection Pin
Mohsen_Emgineer200412-Jun-07 16:31
memberMohsen_Emgineer200412-Jun-07 16:31 
GeneralRe: connection Pin
Liam Cavanagh13-Jun-07 2:14
memberLiam Cavanagh13-Jun-07 2:14 

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

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

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