Windows Mobile 5.0 State and Notifications Broker - More resources

You Can Take it With You

Syndication

News

  • Don't miss the next Windows Mobile Webcast... Unit Testing for Mobile Devices: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032382824&EventCategory=4&culture=en-US&CountryCode=US.

As I mentioned in my post the other day, my latest column discusses some of the more fundamental uses and capabilities of the State and Notifications Broker. The State and Notifications Broker is one of the most significant new features of Windows Mobile 5.0and makes things like tracking changes in network connectivity, battery state and much more are now easily available through the State and Notifications broker.

If you would like to see a live demonstration of using the State and Notifications Broker to detect changes in network connectivity, checkout Maarten Struys latest Webcast, Creating a Windows Mobile (LOB) Application : State and Notification Broker and Message Interception. It will be broadcast live on Wednesday 22-February-2006 at 11:00 AM Pacific Standard Time. It will of course be available for on-demand viewing indefinitely.

The column and webcast should work well together to give you a solid understanding of how to work with the Windows Mobile 5.0 State and Notifications Broker.


Posted Feb 22 2006, 07:12 AM by jim-wilson

Comments

Jim Wilson wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 01-24-2007 5:33 AM
Rupesh;

The exact way you do it depends on whether you’re using managed or native code.

In managed code you check to see if a phone call is active by checking the value of SystemState.PhoneCallTalking. To be notified that a call is entering or leaving the active talking state do the following:

SystemState _phoneCallTalking; // should be class-level not local to a function
_phoneCallTalking = new SystemState(SystemProperty.PhoneCallTalking);
_phoneCallTalking.Changed += new ChangedEventHandler(MyPhoneCallTalkingHandler);

For native code you use the following 4 constants from snaphi.h
SN_PHONECALLTALKING_ROOT
SN_PHONECALLTALKING_PATH
SN_PHONECALLTALKING_VALUE
SN_PHONECALLTALKING_BITMASK

Use the RegistryGetDWORD function to retrieve the value and the RegistryNotifyWindow function to be notified of a change in state.

You can find a detailed description of working with both the managed and native APIs at http://msdn2.microsoft.com/en-us/library/aa456240.aspx.

That should do it :-)

- Jim
Jim Wilson wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 01-24-2007 5:36 AM
Oh, I forgot to include this...

You can find the complete list of Windows Mobile 5.0 state values at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mobilesdk5/html/wce50constatstorbaseproperties.asp

-Jim
David Stroop wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 02-09-2007 3:05 PM
I really would like to use managed code to receive notifications of changes to
[HKEY_LOCAL_MACHINE\System\State\Hardware]
"Bluetooth"=dword:00000001.

But it looks like I can only do that in native code.

Is that true?

David
Jim Wilson wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 02-12-2007 8:57 AM
David;

You can receive notifications in managed code to any State & Notifications value. The SystemState class and SystemProperty enum that we most frequently use provides simplified handling for the common pre-defined state values but it's not the only way to receive notifications.

For values that are not covered by SystemState/SystemProperty, you can use the RegistryState class which allows you to explicitly specify the registry key and value that you'd like to monitor. For the case you've mentioned you'd do the following.

RegistryState _hardwareBluetooth;
void Form1_Load( ..., ...)
{
_hardwareBluetooth = new RegistryState(registryKey, registryValueName);
_hardwareBluetooth.Changed += new ChangeEventHandler(HardwareBluetoothChanged);

int theValue = (int)_hardwareBluetooth.CurrentValue;
// ....
}

Other then the constructor, using the RegistyState class is just like using the SystemState class. In fact, the SystemState class actually contains a private instance of the RegistryState class that does all of the work. The SystemState class is just a slightly more friendly wrapper

Hope this helps.

-Jim
Jim Wilson wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 02-12-2007 8:59 AM
Ooops...

I forgot to include the two constant definitions that the RegistryState constructor uses in the above sample code.

const string registryKey = @"HKEY_LOCAL_MACHINE\System\State\Hardware";
const string registryValueName = @"Bluetooth";

There... that should do the trick. :-)

-Jim
David Stroop wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 02-12-2007 10:02 AM
That worked.

For completeness, one also needs
public void HardwareBluetoothChanged(object sender, ChangeEventArgs args)
{
// registry changed
// RegistryState state = (RegistryState)sender;
}

Thanks,
David
Jim Wilson wrote re: Windows Mobile 5.0 State and Notifications Broker - More resources
on 02-12-2007 10:11 AM
David;

Agreed - I was focusing on the RegistryState class usage itself but the Changed Event handler method does complete the story. :-)

Thanks,
Jim

Add a Comment

(required)  
(optional)
(required)  
Remember Me?