Using PhoneCellBroadcast in WM5 for cheap location aware applications

Using PhoneCellBroadcast in WM5 for cheap location aware applications

A couple of weeks ago a fellow MVP, Mitch Denny, asked me a question about the Notification Broker in Windows Mobile 5.  For anyone not familiar with the Notification Broker it is a mechanism where you can not only query system information about the device, but you can also register for notification when a system property changes.  Anyhow, Mitch’s question was regarding the PhoneCellBroadcast property and the fact that it didn’t seem to be returning any data. 


Despite talking over Messenger I did my best job to look puzzled having never really played around with that particular property. Mitch proceeded to explain that it was supposed to access broadcast messages from the current cell the mobile was connected to.  Interestingly enough, Australia is one of the few places in the world where the networks appear to broadcast useful information.  To access this information you firstly have to do the following (the steps here apply to Windows Mobile 5 and have been tested on both the K-Jam and JasJar – let me know if it does/doesn’t work on other devices):



Start -> Settings
Select Personal tab -> Phone
Select More tab -> Tick the Broadcast Channels checkbox and hit Settings button
Tick the Receive channel list checkbox
Select English from language dropdown
Hit New… button
Enter Cell (or any other description) into Name textbox and 50 (this varies in different countries but should be correct for Australian networks) for the Channel number
Hit Ok
Make sure the new entry in the Select item to receive: list is checked
Hit Ok
Hit Ok (again, which should take you back to the main settings page)
Wait 10-20 secs and you should receive a notification bubble with the name of the Cell (eg Subiaco) in it.


Ok, so now that we can see the cell broadcast, what can we do with it.  Well firstly, the usage is going to be somewhat limited because although in some cases the cell name is the suburb, in others it is a cryptic abbreviation (eg EstVicPrk for East Victoria Park) or simply a placeholder (eg New Coverage which we got somewhere around North Fremantle).  This said, I’m sure that someone will come up with a use for it so the important thing is that we can extract the contents of this message.


For those familiar with the Notification Broker you will be aware that we can extract information about the current system state using the following lines of code:



Dim x as new Microsoft.WindowsMobile.Status.SystemState(SystemProperty.PhoneCellBroadcast)
MsgBox(x.CurrentValue())


Alternatively, if we want to be notified every time this property changes we can attach an event handler to the Changed event of the SystemState object.  Unfortunately there is a little documented issue with using either of these techniques.  Unless the PhoneCellBroadcast property has a value you will either experience a NullReferenceException or the CurrentValue method will return nothing.


To get this property to function correctly we need to tweak a registry setting which was kindly given to me by one of the mobility guys, Paul Kormann, at Microsoft. By default if you look at the key HKEY_LOCAL_MACHINESoftwareMicrosoftInboxSvcSMS you will see that there is an entry TreatImmediateModeCBAsClass0SMS which has a value of 1.  As the entry implies a value of 1 (ie true I guess) implies that the system should Treat Immediate Mode Cell Broadcasts (ie the network messages we were receiving earlier) as Class 0 SMS.  As I found out from my quick read of the SMS FAQ a Class 0 SMS is designed to be displayed then discarded (versus a Class 1 (ie normal) SMS which is stored).  The net result is that having this value set gives us the notification bubble we saw from the steps above.  Changing the value of this entry (using either a remote registry editor or a registry editor for the device) to 0 should mean that we can access these messages using the notification broker. 


Ok, so I was happy with this and proceeded to change the registry value.  Unfortunately it didn’t immediately work for two reasons.  Firstly in my playing I had disabled the Broadcast channels (the first checkbox in the above steps).  Secondly I hadn’t reset my device.  So the steps to get this to work are:



Complete steps above to enable Broadcast channels
Change Registry value for TreatImmediateModeCBAsClass0SMS
Reset device


Now for the bad news.  I was pleasantly surprised when this worked on my K-Jam so I was quick to pass on the news to Mitch.  Unfortunately try as he might he couldn’t get the same instructions to work on his JasJar.  John also tried this on the SoftTeq JasJar with the same result.


While we were experimenting we did find a useful area of the Registry. HKEY_LOCAL_MACHINESystemState contains a number of keys relating to the current state of the system.  Of particlar interest to what we were doing was the Phone key.  On my K-Jam, after applying the steps above, there was an entry for Cell Broadcast which contained the most recent cell broadcast.  However on the JasJar this entry never seemed to exist.  Interestingly enough when Mitch manually populated this entry the value was accessible in code (as if it has been correctly received via the notification broker).


I hope this is useful to anyone interested in delievering a cheap location aware application.  If anyone can get this to work with the JasJar please let us know.

Enterprise Development using Patterns and Practices

Enterprise Development using Patterns and Practices

Last night, John presented an overview of the Enterprise Library to the Perth .NET Community of Practice.  It was clear that there were mixed experiences within the audience ranging from those that were working with v2 of the library (1 or 2), those working, in anger, with v1 of the library (half a dozen or so) and those that either won’t admit to it or weren’t using it at all.  Having been involved with a large scale application that didn’t use either the application blocks or the Enterprise Library I can only commiserate with those in the same boat – word of advise… spend the time and money to incorporate the Library into your application.  This doesn’t need to be done all at once, you can bring it in piece by piece, but in the long run it should save you time and ensure your product is more reliable.


Ok, so this said, there are some other things that you should really check out, particularly if you are starting a new application and want some guidance on how to build a consistent user experience.


Composite UI Application Block (here)


Mobile Baseline Architecture Toolkit (here)


Also, touch base with John’s blog as he looks at the various application blocks in the Enterprise Library itself. (For those that missed the presentation last night, the slides should be available on the user group site by the end of the week).