10 Apr 2007

State and Notification Broker API

If you need to monitor the various aspects of the state of a Windows Mobile or Smartphone, you can use SNAPI...
Here they are the more interesting on WM5.0 SDK, you need to:


  • Get ActiveSync's current state : ActiveSyncStatus
    - Error -None -Synchronizing
  • Get if a camera is attached and enabled : CameraPresent
  • Get the number of network connections that are currently connected. Very interesting if you want to know if you are connected to a WIFI network : ConnectionsNetworkCount
  • Get the orientation of the display : DisplayRotation
  • Get the number of unread SMS messages : MessagingSmsUnread
  • Get the mobile device phone number : OwnerPhoneNumber
  • Get the phone GPRS coverage : PhoneGprsCoverage
  • Get if the SIM is valid or not : PhoneInvalidSim
  • Get if there is new missed call : PhoneMissedCall
  • Get the number of missed phone calls : PhoneMissedCalls
  • Get if the SIM is installed in the mobile device : PhoneNoSim
  • Get the name of the mobile operator : PhoneOperatorName
  • Get if the phone is currently in roaming mode : PhoneRoaming
  • Get the phone signal strength : PhoneSignalStrength
  • Get the battery power level : PowerBatteryStrength
  • Get information relating to Calendar, Contacts, and Tasks, a lot of properties and events associated are available...




To use State and Notification Broker API, you will need to add two assemblies to your project : Microsoft.WindowsMobile and Microsoft.WindowsMobile.Status.



An other interesting thing with SNAPI is you can add an event handler when a property changed and obtain the new value. Here an example of code below: (this example of code can be transposed for the other properties).

SystemState batteryStrength = new SystemState(SystemProperty.PowerBatteryStrength);
private void Form1_Load(object sender, EventArgs e)
{
batteryStrength.Changed += new ChangeEventHandler(batteryStrength_Changed);
}
void batteryStrength_Changed(object sender, ChangeEventArgs args)
{
BatteryLevel batteryLevel = (BatteryLevel)args.NewValue;
}

2 comments:

Anonymous said...

Hi,

Thanks for the advice, but using the SystemProperty.OwnerPhoneNumber.ToString();
always gives me the string "ownerPhoneNumber" and not the actual phone number. Why is this?

Fabien Decret said...

Hi,

Try this, it must work better:
(string)SystemState.GetValue(SystemProperty.OwnerPhoneNumber)

See you soon

Fabien