Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Windows Phone 7 App–ContactShare

Blogs

Mike Taulty's Blog

Elsewhere

Archives

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.

aboutPageImage

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 Smile 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;

image

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;

image

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;

image  image

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;

image

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;

  1. You have to remember that it’s Silverlight 3 today (4 is coming Smile) 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.
  2. Debugging on the Phone is pretty good but I feel it could be a little better. Specifically;
    1. Having to keep unlocking the phone to launch the debugger is a bit painful.
    2. 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.
    3. 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.
    4. I did come across the idea of the debugging console though which was useful.
  3. State management on the phone takes a couple of goes to figure out. My recommendation would be to do something like;
    1. Build a simple app with 2 pages that navigate to each other.
    2. Set breakpoints in your code for;
      1. PhoneApplicationPage.OnNavigatedTo
      2. PhoneApplicationPage.OnNavigatedFrom
      3. PhoneApplicationPage.OnNavigatingFrom (note the importance of this one is that it lets you know if you have a back navigation in progress)
      4. Application.Launching
      5. Application.Activated
      6. Application.Deactivated
      7. Application.Closing
    3. And exercise your code until you fully understand when these events happen in terms of the lifecycle of the application on the phone.
  4. 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;
    1. 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.
    2. 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.
  5. 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.
  6. 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.
  7. Some of the things coming in the forthcoming ‘Mango’ release would be welcomed here. Some thoughts;
    1. Direct access to the camera might be interesting.
    2. 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 Smile) – you can search for ContactShare on the marketplace to give it a whirl and, naturally, it’s free.


Posted Tue, Jun 7 2011 11:52 AM by mtaulty

Comments

Geoff Hirst wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 12:01 PM

What's happened to Microsoft Tag? Surely a far better solution than QRCodes? Or is it just that QRCodes are more widespread?

Going to get your app and see what happens.

cheers nice article.

Darren wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 12:02 PM

Awesome idea. Shame you couldn't demo it with two devices, but I like the improvisation

Rich O'Connor wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 12:08 PM

Nice one Mike!

mtaulty wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 3:38 PM

Geoff,

Good question and I must admit that I did start off with Microsoft Tag but I got a bit bogged down.

Maybe I don't understand it properly but this page;

tag.microsoft.com/.../implementationguide.aspx

suggests that there is a vCard type of tag but as far as I understand the Tag system you have to use the "Tag Manager" to create the tags up-front.

That is, it didn't look to me like there was a solution for the end-user dynamically creating their own tag on their own phone. It looked like someone would have to register on the website, create a tag and then install it to their phone.

To me, that seems much more complex than being able to dynamically create a QRCode on the phone.

Mike.

Steve Fenton wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 4:00 PM

Just thought I'd add to the tag question.

The QR Tag has the advantage of actually being able to contain data, whereas the Microsoft Tag is like a URI that points to the data.

mtiede wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 5:35 PM

So, I just tried it.  And it LOOKS like the information I put in about myself is NOT from the People hub.  Seems a shame to have to enter it twice.  Ought to be able to at least load it from "ME", or have the controls give me a list to select from my contacts instead of having to type it again.  And then if I change my email address, which I just did, I have to remember to change it both places.

What do you think?

mtaulty wrote re: Windows Phone 7 App–ContactShare
on Tue, Jun 7 2011 5:40 PM

I'm not sure there's a chooser that will provide an application with a set of contact details. I think there's only one for phone number, one for email and so you'd have to repeat this process at least twice.

Let me check...but you might have noticed that I have "Save Email" and "Save Phone Number" for the same reason - I don't think there's a task on the phone that will let me save both in one go.

Mike.

James Coulter wrote re: Windows Phone 7 App–ContactShare
on Wed, Jun 8 2011 11:14 AM

Nice article, Mike. Shame the video clips don't actually play on a WP7 phone. Any chance of showing us some code snippets for the benefit of us Silverlight/WP7 dev newbies?

peSHIr wrote re: Windows Phone 7 App–ContactShare
on Thu, Jun 16 2011 10:07 AM

Mango allows (readonly) access to all contacts in People Hub, so you could easily copy your own Me info from there and use it in this app without the need to enter it other than in People Hub/Me.

mtaulty wrote re: Windows Phone 7 App–ContactShare
on Thu, Jun 16 2011 3:36 PM

peSHIr,

Yep, that will make it easier to build this kind of app in 'Mango'

Mike.

Mike Taulty's Blog wrote Windows Phone App–ContactShare Updated for ‘Mango’
on Thu, Sep 1 2011 7:13 PM

I’d managed to get my Windows Phone upgraded to the ‘Mango’ developer beta 2 release and so I thought