Ales Rosina's blog

shelastyle.net
Subscribe

Entries tagged 'wp7'

Simple error reporting on Windows Phone 7

NEW YORK - OCTOBER 11:  A person holds a new  ...

If you’re developer, you’re familiar with user reports as “your app just crashed.” And before you can find out what the user was doing, it can last for a few hours or even days. This is even worse on mobile applications – if user will get two or three unexpected crushes, he will simply throw your app away and download a new one (don’t fool yourself, that your app is the only one with one super-cool functionality) . So getting error reports from your app is crucial for user satisfaction.

Now, let’s see how we can achieve this on Windows Phone 7. First of all, we must take into consideration how to get reports – we could use email, we could use some web service to post error reports or just store it locally and forgot about it. Sure, the last option is pretty much the same as if we didn’t have any reports and the second is also not very reliable (maybe user has no data coverage at a time of crash, maybe he’s running app in airplane mode or even a web service is down) so the only simple option is sending by email. So let’s take a look at that option.

I’m using this kind of approach in my apps with a button “report errors” in about page. This approach is widely used (eg. it’s used in Twitter and Facebook app), so I guess users are willing to use it. Let me just warn you here, that even if you have this error reporting implemented, you should still use try-catch blocks on risky parts of code.

In this example (you can download sample project here) we are going to use IsolatedStorage and Phone Task for sending email.

Firstly, in WP7 apps you can find App.xaml with codebihind in App.xaml.cs where we’ll do most of the work. In this file (which is generated by Visual Studio) you can find event called Application_UnhandledException, where you shoud add this code:

private void Application_UnhandledException(object sender, 
ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debugger.Break(); } else { try { using (IsolatedStorageFile file =
IsolatedStorageFile.GetUserStoreForApplication()) { using (StreamWriter sw = new
StreamWriter(file.OpenFile("error_log",
FileMode.Append, FileAccess.Write))) { sw.WriteLine("{0}\n{1}\n{2}\n------------------\n",
DateTime.Now.ToString(),
e.ExceptionObject.Message,
e.ExceptionObject.StackTrace); } } } catch (IsolatedStorageException ex) { } } }


Now we just need to add a button for sending reports, where we will implement sending email:

private void buttonSendError_Click(object sender, RoutedEventArgs e)
{
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
    {

        if (!file.FileExists("error_log"))
        {
            MessageBox.Show("Yeah, there are no errors!");
            return;
        }
        try
        {
            string errorLog = "";
            using (StreamReader reader = new 
StreamReader(file.OpenFile("error_log", FileMode.Open, FileAccess.Read))) { errorLog = reader.ReadToEnd(); Microsoft.Phone.Tasks.EmailComposeTask em = new EmailComposeTask(); em.To = "your.reporting@email.com"; em.Subject = "my super cool app has crashed! :("; em.Body = errorLog; em.Show(); } file.DeleteFile("error_log"); } catch (IsolatedStorageException ex) { } } }


And we’re done! This will open up user’s new email dialog. One downturn of send emails is, that you cannot test this in emulator, only on real device.

That’s it! If you have any comments, leave them bellow or just download sample project here.

Enhanced by Zemanta


   

author: Aleš Rosina | 2 Comments | Tags: , , ,
23
March
2011

Windows Phone 7 presentation at MobileMonday

NEW YORK - OCTOBER 11: A person holds a new Wi...

I just had a presentation about Windows Phone 7 on (very cool) event MobileMonday Slovenia, which is held every month in Ljubljana’s local cyber-geek-place called Cyberpipe.
In this presentation I’ve covered basics about WP7, how the user interface is structured with some basic technical details.
I’ve shown a quick demo on how to develop and design a very simple app calling some external web service.
Just to quickly recap what I’ve done in demo:
Calling external service with adding Service Reference (which is also included in zip file – download from my skydrive) and showing async calls to service. After that, we’ve also seen some design stuff – that is, how to use Expression Blend for changing basic functionalities and creating animations.

We’ve also discussed how to publish apps on Marketplace and how to monetize them.

That’s that and check also my slides, maybe you’ll find them useful:

View more presentations from Ales Rosina
 
Enhanced by Zemanta


   

author: Aleš Rosina | No Comments | Tags: , ,
01
March
2011

Windows Phone 7 for developers

This Saturday I had a presentation at MobileCamp Ljubljana about upcoming Windows Phone 7. Since I like minimalistic presentations let me add a few words besides slides:


As you can see in a lot of videos around web, UI is structured a little differently as we are used to (eg. iPhone, Android, Maemo, Sybian, …). On home screen (or start screen) are tiles, which are “active” – they are animating and shows a lot of information as it can be best seen on videos. Microsft also invented something called hubs – actually these are apps, which are scrollable left and right.
I did a very simple demo at my lecture, you can download it here. It’s very basic app, which uses WiFi-tocke.si service and shows a list of spots in my area. There is no advanced code, just basic list and one subpage for showing details of each hotspot. Try it out and if you have any questions, leave a comment.

And just to refresh – for development you need a free developer tools and you can grab them here: http://developer.windowsphone.com/. If you are interested in more step-by-step guide, check out first and second lecture from MIX10 conference.

Ok, now let me just write a few words how to distribute your apps. As you probably know, you will have to use Marketplace (similar to iPhone AppStore). There are also a lot of countries, where you cannot apply for developer account due to restrictions of payments. Check my slides for full map. A lot is yet unknown, since Microsoft is promising more details about Marketplace in May. Check out this video of a session from MIX10 for more details.

I’ll also publish video of my lecture from MobileCamp Ljubljana when it will be online. Stay tuned :) Until than you can check what folks are tweeting about #mobilecamplj.

UPDATE: I just found out, that videos are finally online, so here’s mine lecture. Video is pretty poor quality, but I think you’ll get the point.

Reblog this post [with Zemanta]


   

author: Aleš Rosina | 1 Comment | Tags: ,
27
March
2010