Windows Phone

My first Windows Phone 7 app development project

Justin James describes why his first Windows Phone 7 application development project was frustrating, surprising, and, ultimately, easy to pull together.

Despite my misgivings, I decided to give Windows Phone 7 development a try. The experience was bad in ways that I did not expect, and good in some areas that I had been concerned about.

The good

The transition to Silverlight

First and foremost, I was wrong about something that I had been very outspoken about: For the most part, Silverlight is not the weak point in the development chain; the Silverlight experience was actually tolerable. Is it perfect? No. Am I now a Silverlight expert? Not by any means. But I have learned in the last several weeks that the amount of Silverlight needed to hash together typical business applications is minimal.

Coming from a WinForms background (with only one minor WPF app under my belt), the transition to Silverlight isn't bad -- you can even still follow the WinForms paradigm if you choose. In a nutshell, the Silverlight ecosystem is filled with folks who really like to talk patterns and practices, and from reading their stuff, it sounds like using Silverlight without following stuff like MVVM will kill you. The reality is, it won't.

Silverlight's supporting technologies Working with Silverlight's supporting technologies, such as RIA Services and WCF, isn't as bad as I thought it would be based on the live demos I'd seen about the technologies. Thanks go to TechRepublic reader Terje Bergesen, who set me straight with his top flight tutorial on using data services from Silverlight. Silverlight tools in Visual Studio 2010

The Silverlight tools in Visual Studio 2010, combined with the Windows Phone 7 development tools, were smooth and functioned just fine. Before I installed the Windows Phone 7 tools, I was concerned that it would install Express versions of Blend and Visual Studio even though I had full versions of both products. Happily, it detected my existing installations and did not install the Express versions side-by-side. This needs to be clarified on the development tools website.

Unfortunately, that is where the good news ends.

The bad

The APIs

The first problem I encountered was that the APIs lack the ability to do many useful things. To be frank, the APIs stink. I was really excited about my original application idea because it addressed my need for an autoresponder for text messages that would also disable the phone's volume while it was on. It drives me nuts when people send me text messages while I'm driving, because I'm tempted to read and answer the messages, but I know that is really dangerous. I was sure that this could be done because I had been to Windows Mobile 6.5 presentations that showed how to send and read text messages, work with the phone's settings, and so on. While Windows Phone 7 is a new platform, I couldn't imagine that it would be less capable than Windows Mobile 6.5.

It's not a phone platform

It turns out that I was wrong. From the developer's standpoint, Windows Phone 7 is not a phone platform. It is a Silverlight client (missing a lot of Silverlight's current functionality) with access to the phone's sensors (compass, microphone, accelerometer, GPS). Any of the things that one associates with a cell phone (other than the vibration device) are inaccessible to your application. Instead of having an API for actually working with text messages, the contacts list, the camera, phone calls, and so on, you have the ability to start those applications and sometimes get results back from them after the user takes some action.

For example, your application cannot send a text message, but it can start the text messaging application and pre-populate the "To" and "Body" of the message (as far as I can tell, there is no way to send pictures or movies -- even those are supported by the phone). Or to work with the camera, you can start the camera application, and if the user takes a picture, your application is given the picture information afterwards. This limitation rules out entire categories of applications -- the kinds of applications that leverage the innate properties of a phone.

It's really ironic that Microsoft is pushing the Reactive system for Windows Phone 7, using it as the preferred way of working with the sensors. It would be an ideal way to work with phone calls, text messages, and other system events to put together some outstanding applications... if only the phone allowed you to do so, and if it was multithreaded so you could have applications running in the background.

If you plan to build a Windows Phone 7 app that depends on phone functionality, I suggest that you really study the API documentation before you commit to the project. Chances are, you won't be able to write the app you want.

Developing my Windows Phone 7 app

I was in a hurry to at least write something but I knew that I had to scale back my plans dramatically, so I headed to Data.gov to see if I could find any data services that I could build an application on. I did not have the time or resources (namely, the server resources) to put together a Web service that did anything useful on the server side. I found a Web service for getting the status of U.S. airports, and it looked easy enough to work with until I hit yet another snag: Silverlight works really great with SOAP Web services, but not so great with REST.

When I did some research on using REST in Silverlight, everything I found said that I needed to get a connection to the service and manually parse the XML and look for what I needed. To add insult to injury, Windows Phone 7 does not support the WCF Data Services stuff out of the box! There is a decent OData-capable library on CodePlex; unfortunately, it has a major shortcoming: It does not support authentication. Since there are not many Web services that are exposed to the Internet that do not require authentication, that renders it useless in far too many circumstances, and you are in the cold.

For my application, I decided to play it quick and dirty and use WebClient to download the data, pop it into an XDocument object (it would never be too large, 2 KB max), and use LINQ to get what I needed from it. And I hit yet another snag. It turns out that someone at Microsoft decided "thou shalt call thy network services asynchronously." I get it -- they don't want someone jamming the phone up for 30 seconds waiting for a server to time out, or a few minutes downloading a big file -- but I believe that decision should be up to the application developer not the operating system. Instead of using a simple call to WebClient.DownloadString(), I was forced to use the less direct asynchronous model, which really makes the code ugly and more difficult to debug and maintain. To make matters worse, the Reactive stuff would have been great here, but it only works with some of the sensors at the moment, so it was out of the picture.

Another cautionary note: The Windows Phone 7 development templates are extremely conservative in the default references in a project in comparison to WPF or WinForms applications to save resources. It is sometimes unclear whether you cannot work with an expected piece of functionality because of a missing reference, or because Windows Phone 7 just does not support that functionality. The documentation is your friend here.

Once I overcame these minor hurdles, my Airport Status Checker application was easy to pull together. I posted the Airport Status Checker application under the MIT License, so you can take a look at the code.

In the second installment of this two-part series, I'll discuss what it is like to work within the Windows Phone 7 ecosystem in terms of getting support and having your application published.

More about Windows Phone 7 development on TechRepublic

J.Ja

Disclosure of Justin's industry affiliations: Justin James has a contract with Spiceworks to write product buying guides; he has a contract with OpenAmplify, which is owned by Hapax, to write a series of blogs, tutorials, and articles; and he has a contract with OutSystems to write articles, sample code, etc.

About

Justin James is the Lead Architect for Conigent.

29 comments
supriyaakg
supriyaakg

Does Windows Phone 7 support standalone Flash Lite 3.x apps? If yes, is packaging from swf to the phone compatible format possible? What format should be the apps for the WP7? I tried to package my FL 3.1 app to a WM 6 compatible 'cab', but only later to be disappointed that WP7 does not support WM 6 compatible apps.

AnsuGisalas
AnsuGisalas

Metasploit and the like. If the given client can't do it, hack it 'till it can ;) But I guess that'd make licensing difficult...

terjeb
terjeb

I have been toying with a project that I wanted to develop for mobile. For the app to be as good as I would want it to be, I would need direct access to the camera and messaging functions for example. If this is not possible with Windows Phone 7, it is bye-bye Microsoft, with an parting comment of "Are you JOKING?".

ps2goat
ps2goat

How does this compare to Android and Apple AppStore development? Is it better than the tools that those OSes provide, even without the data services being integrated?

Jerome.Wright
Jerome.Wright

You know what? I'm not getting involved. I get to spec hardware when I'm doing Corporate programming jobs. I will be specifically demanding Android for the time being, then move over to MeeGo when it reaches maturity. Windows Phone 7 is 2 years late and 20 functions short, and it's neither in my, nor my clients', interest to waste time and effort trying to overcome serious technical failures. Even more annoying is the lack of break out from the phone form factor. I often have call for applications to work on tablets in the stockrooms and on phones everywhere else. WP7 is committed to increasing the time and effort required to do that, too.

daboochmeister
daboochmeister

I'm curious what you would have called major hurdles. Forced to use asynch, no APIs to interact with any phone-related functions, etc. ... those aren't major? Not being snarky, honestly curious. What kinds of things would be major to you?

Justin James
Justin James

WP7 does not support 3rd party runtimes like Flash. The browser might support Flash though... I haven't tried. J.Ja

Justin James
Justin James

I know what you mean! I think that for what WP7 *does* do, it is a good experience, better than Android for sure (other than the emulator). But it is so limited, it is not a real choice for many projects. J.Ja

Justin James
Justin James

Android is wide open, but the development experience suffers a bit (strictly my *personal opinion* here) from the dependence on Java. My *personal* experience with the Java ecosystem is that it is very difficult to get a handle on where to start, which library to use, etc. I've never coded for iPhone, I've seen some demos. From the demos I have seen (all at least a year ago, so they may be outdated now), the iPhone development does not look as smooth for the functionality that WP7 does support. J.Ja

Justin James
Justin James

That's a fair question. The async thing isn't much of a big deal, because it takes about 2 minutes to learn how to work with the async model in most cases. The lack of APIs around the phone functionality are definitely showstopper if you are not aware of them (ie: you committed to a project that needs it), but once you know about it, you just take it into account when choosing projects to do. Some of the things I would call "major" hurdles: * A non functioning or buggy emulator (although the current emulator borders on "major" with its inability to simulate the GPS, accelerometer, etc.) * Not being able to debug from within the same tool that you write the code (for example, until a year or two ago, writing BlackBerry apps had that workflow) * Having to learn a new language that I normally would have no need for (Objective C comes to mind) * Having to buy a piece of hardware to develop. WP7 development definitely has a "major hurdle" here if you are testing GPS, accelerometer, etc. iPhone development does too, considering that if you are writing native iPhone code, you need a Mac and XCode. * Needing to pay money for tools. * Incomplete, missing, or incorrect documentation. I suspect that what I call a "major hurdle" is probably a "showstopper" for a lot of other people, and what I call "minor" in many cases others will say is "major". J.Ja

daboochmeister
daboochmeister

Justin, did you discover anything at the capability level that would explain why they released it without offering encrypted connection to Exchange? Are the cryptography APIs "cryptled" (ha ha)? E.g., is it unable to connect to HTTPS servers, process certificates, etc.? Or was it just a (arguably weird) prioritization decision on features?

gak
gak

As for the lack of access to the phone features, it looks like the lack of access to the file system in the desktop Silverlight. Not everything can be allowed if security is required. I wish Windows 7 well, but I am afraid Android will win and after that some unified true Linux OS will dethrone it. I would be glad to be wrong, I like Silverlight and .NET in general.

Justin James
Justin James

There is a follow up piece coming next week (if not earlier, it is already in Mary's hands) on the other side of the development story, working with App Hub. Incidentally, as of last night I have a second app (and this one is actually a paid app) in the App Hub marketplace. Developing for WP7 is stupid simple if you know C# & .NET (even without prior SL or WPF experience), the problems are the API limitations. Last night I saw a presentation on XMA game development, specifically for phones. I was drooling. I really hope the WP7 does well, because if they can get the API beefed up in terms of working with the phone functionality, it has potential to be the best mobile platform to develop against right now. But at the moment, it's all "potential" with little reality. J.Ja

supriyaakg
supriyaakg

What do handsets mean when they say they support Flash Lite 3? And what is the difference between WM7 and WP7?

terjeb
terjeb

I am working on evaluating a mobile platform for a client, they are a few weeks away from making a decision. They have a rather simple need (in addition to traditional data-entry stuff which I assume WP7 does fine), and that is assisted photography. Simple really - they are out in the field and taking pictures of very specific items. Each item has a specific shape, and to assist with automatic image analysis, we've been asked to look at the ability to "paint" the different shapes onto the phone for picture taking. The person selects what item it is he is taking a picture of, the outline shows up on the screen, he aligns the image to fit with the helper-outline, and voila, the automatic analysis of the image becomes a lot easier. I was going to evaluate WP7 for this next week, now I am not even going to bother. The client I am talking to is going to be buying some 1000-1500 phones after new-years for this. Clearly they will be Android phones. Sheesh, I wanted to do this in SL.

Justin James
Justin James

Sorry, I don't know why encrypted Exchange doesn't work. In fact, that's the first time I heard that. As far as I can tell, it handles HTTPS just fine. J.Ja

Justin James
Justin James

... is loaded over the air, like it is on Android (and presumably iOS and BlackBerry). J.Ja

gak
gak

that the jack is as simple as signing an application with a MS key.

AnsuGisalas
AnsuGisalas

that there's a jack that provides access... Must be possible to load new firmware, after all... Of course, the prospect of fudging a connection through an unknown jack is pretty cinematic. Helps if it's a USB of course... But someone should post a challenge to the hacker community.

Justin James
Justin James

I've heard of some folks who have found ways to get to the bottom layer, I believe that the way they did it was hacking the communications with a PC. But I am not sure what access they got or how much. Since your code is Silverlight, anything on the phone, by default, is sandboxed and easily contained. J.Ja

AnsuGisalas
AnsuGisalas

How can it not be a phone OS... unless there's a phone OS underneath it? Has to be something running the hardware too, right? Kernel hacking?

Justin James
Justin James

... particularly games, and things that integrate into the Xbox ecosystem. If I were a hardcore gamer, this would be the device for me, and if I was a game developer I'd be working 60 hours a week tying my products to the phone (assuming I thought the effort was worth it). That being said, their issue here is that few people are going to buy a phone just for that integration, and the WM 6.X devs who have been waiting on WP7 to decide if they will migrate to WP7 or jump ship to iPhone, Android, or BlackBerry are, in many cases, going to see no overwhelming reason to go to WP7 when in many ways, it is less capable than WM 6.X from the developer's viewpoint. J.Ja

AnsuGisalas
AnsuGisalas

Srsly! Apps are important in the smartphone world, are they not? Especially apps that can do smart things...

Justin James
Justin James

I will definitely let folks know when it's coming. I was just as disappointed at this as a lot of other people, it makes it imposible to do a large number of applications. J.Ja

daboochmeister
daboochmeister

Justin, I do augmented reality stuff, and the above means no go for me ... will you pls blog when you see a roadmap or timeline for them adding this capability? thx.

Justin James
Justin James

You have the right understanding. You will NOT be able to add an overlay to it... all you can do is launch the camera app and get the picture back if they take it. So it sounds like your app is NOT possible. :( J.Ja

terjeb
terjeb

What I need is to put an overlay onto the camera view before the picture is taken, so that the user can take advantage of that overlay to frame the picture correctly. I might not have phrased that well. From what I understand I can only hand control to the camera app, not change what it shows the user before the picture is taken.

Justin James
Justin James

That app *might* be possible in WP7 (I don't understand the specifics enough to say for sure). Basically, your app can tell the phone to open the camera application, and if the user decides to take a picture, that is passed back to your app. I hope that's enough to do what you want to do, since I know that SL is one of your specialties and WP7 dev, when it *can* do what you want, is nice. J.Ja

Editor's Picks