I wanted to have a bit of fun with Windows Phone 7 and so I thought I’d build a little application as a background task.
One thing that I miss from previous phones is that scenario where you meet someone and want to quickly swap contact details. With previous phones there was a notion of “beam contact” which relied on an IR link but that seems to be old hat these days and so I thought I’d see if I could come up with something a little more “modern” that would work on the phone without requiring a cloud connection.
I daresay someone’s done this already but, regardless, I had fun working at it and decided to try and make the idea of “photographing the contact” work. This led me to look at QRCodes and, specifically, I looked around for the “right” way to represent some basic contact information such as;
- first name
- last name
- email address
- phone number
in a QRCode and the best thing that I could find which seemed to fit was a MECARD which takes the format of a string looking something like;
With that decided, I needed a library that would let me encode/decode QRCodes on the Windows Phone 7 and I very quickly found Google’s excellent zebra crossing library and a port of it over to the Windows Phone 7 and Silverlight over on CodePlex.
With all that in place, I was ready to try and build a little app. It ended up working as below.
Creating a QRCode for your Contact Details
When the application runs up for the first time, it asks for contact details;
and as soon as you’ve typed in anything and hit the Store Changes button it persists those details into isolated storage and the next pivot item along will change from displaying a place holder to displaying a QR code that represent your contact details;
When the application starts up in the future, it will spot that it has persisted stage and switch straight to that QRCode pivot ready for someone else to take a photo of it on their phone and import it into their contacts. Speaking of which…
Importing a QRCode to Contacts
One way of importing a contact from someone else’s phone is to get them to run the app which will quickly launch and display their QRCode and then you run the app and switch to the next pivot item along;
where’s there’s a button that will let you take a photograph and then import it as a contact. Once the contact is imported, there are context menus that let you save the telephone number or the email address that you just imported using the standard experience on the phone.
A Quick Demo
There’s nothing like a quick demo for bringing things to life so here’s a little video of the app in use;
The other way of importing a contact is to start with the camera, take a photo and then my app hooks into the pictures extensibility on the phone so that you can launch my app straight from the camera.
This isn’t in the version that’s in the marketplace today (I’m currently in the process of updating) but it does provide a second path to the same functionality;
That’s it – not a whole lot to it but I did pick up one or two things along the way…
Lessons Learned in Building for the Windows Phone 7
In putting this together, there’s a few things that I learned about the phone which experienced developers will already know but I’ve not been building phone apps since the very early days so I thought I’d share my top thoughts;
- You have to remember that it’s Silverlight 3 today (4 is coming ) so there were a few places where I felt that I wanted to use some feature (e.g. StringFormat on my bindings) and I couldn’t.
- Debugging on the Phone is pretty good but I feel it could be a little better. Specifically;
- Having to keep unlocking the phone to launch the debugger is a bit painful.
- Having to do the Zune/WPConnect dance every so often soon becomes second nature but it’s a step that it would be nice to be able to avoid.
- Not being able to “attach” to an existing process on the phone makes it kind of tricky to debug scenarios where you can’t just launch your app from the debugger. The specific scenario for me is extending the pictures hub where you can’t launch your app under the debugger.
- I did come across the idea of the debugging console though which was useful.
- State management on the phone takes a couple of goes to figure out. My recommendation would be to do something like;
- Build a simple app with 2 pages that navigate to each other.
- Set breakpoints in your code for;
- PhoneApplicationPage.OnNavigatingFrom (note the importance of this one is that it lets you know if you have a back navigation in progress)
- And exercise your code until you fully understand when these events happen in terms of the lifecycle of the application on the phone.
- There are certain things on the phone that cause you a minor headache when you’re trying to work in an MVVM way. Specifically for me;
- If you’re using launchers/choosers then you have to have specific instance variables on your PhoneApplicationPage class and then you need to find a way to route that work to your view models.
- You have to override OnNavigatingFrom etc. on your PhoneApplicationPage class so that means that you have to find a way of routing that to your viewmodels etc.
- You need to take some care with fonts, icons, brushes etc. so that they will work in different themes. Generally, I just stuck to the standard system resources but I did find this article on using opacity masks very useful.
- I found myself bringing in some of the Expression Blend samples library to try and support some of my bindings to events/commands – specifically the InvokeDataCommand that is part of that library.
- Some of the things coming in the forthcoming ‘Mango’ release would be welcomed here. Some thoughts;
- Direct access to the camera might be interesting.
- At the moment my app has to offer “Save Email” and “Save Phone” options because there are two separate tasks relating to this. It’d be nice if the contacts access in ‘Mango’ would allow this to be streamlined a little.
All in all – a lot of fun. It took me a few hours or so to put that app together but I daresay quite a bit of that was in trying to fathom out a few things on the Phone that I wouldn’t need to re-learn the next time around.
Let me know if you try it and find it working (or not ) – you can search for ContactShare on the marketplace to give it a whirl and, naturally, it’s free.