Tuesday, April 24, 2007

Free Smartphone "Notes" with ActiveSync/DirectPush Support

A former Blackberry user, I'm now running Windows Mobile Smartphone on a Blackjack. I love most things about Smartphone. But I miss the Blackberry "notes" integration with Exchange and Outlook. I used the notes feature constantly, managing all sorts of unstructured lists, and I liked being able to work on them on the desktop and know the changes would be propagated to the Blackberry and vice versa.

So I decided to write a little notes application that would sync with Exchange. If you like this idea and want to try the app, but don't want to hear any more geekspeak, you can get the app and instructions straightaway from here.

If you're still reading, here's what I did... The Pocket Outlook Object Model, which is the first stop for manipulating Outlook/Exchange data on the Smartphone, does not support note items. I wasn't sure if the Windows Mobile MAPI APIs covered notes, and I didn't really want to go that route as a MAPI novice, having heard many MAPI integration tales, none of the pleasant.

The Outlook Web Client accesses notes via AJAX, hence there is a web service endpoint of some flavor that can manipulate notes (Outlook can obviously get this data via HTTP too, since it can be instructed to operate in that mode). I could have sniffed/scraped that interaction ... but I wouldn't the get DirectPush I was jonesing for.

I took an easier route, and chose to store my notes as delimited strings in the body of a Task called "My Notes"

Since Exchange, Outlook, ActiveSync, and DirectPush take care of syncing my Tasks folder, I don't have to worry about that. And Tasks are first-class entities in the Pocket Outlook Object Model, so reading or writing one in C# is about 3 lines of code.

This approach worked well. I built a UI for the Smartphone using TextBoxes, put in the parsing logic, and I was set. On the Outlook side (or Outlook Web), I just open up the task called "My Notes" and there are all my notes, delimited by the same string. I can edit them, save, and the changes are propagated.

Only two wrinkles showed up.

The first is that Outlook 2007 is lazy about syncing the Tasks folder with Exchange, at least when it's set up to connect over HTTP. I cut my app out of the loop completely when testing this, by running Outlook 2007 in one window, and Outlook Web Client in another window. Web client read and committed changes to tasks immediately, while in order to refresh tasks in Outlook, even restarting Outlook did not always work. So, bummer... for now, it's an FYI.

The other interesting bit was the syncing logic in the phone client. The goal was to have the data saved and restored (when updated from the Exchange side) as automagically as possible. I've commented the relevant code, most of which lives in the Notebarn_Activated event handler, so you can take a look at the source if you like.

Any time you switch away from the app, or edit a note in full screen mode, your notes are saved, and any time you switch back, if Exchange has updated the Task data but you haven't, your notes are reloaded from the Task. I've tested various approaches and this one has worked the best for me.

I hope it works for you too. The project page (with source) is here.

47 comments: