Summary of Windows Phone Mango Posts#

mangoI’ve been spending the last few days reading and testing some of the new features in Windows Phone Mango and also writing a bunch of articles sharing some details.  Here is a summary of the articles I have written so far.  With over 1500 new APIs in Mango, I’m sure I will have some more articles so I will continue updating this list as I write more. 

  1. Windows Phone 7 And Multitasking Revisited
  2. Windows Phone Multitasking - Fast Application Switching
  3. Windows Phone Multitasking - Scheduled Notifications
  4. Windows Phone And Database Support
  5. New Windows Phone Device Status APIs
  6. Windows Phone Launchers & Choosers
  7. Augmented Reality And Windows Phone 7 Part 2

Comments or feedback on any of the articles, feel free to contact me here or via twitter @MarkArteaga!


Thursday, June 30, 2011 4:56:49 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Windows Phone - Launchers & Choosers#

Launchers and Choosers have been around since the first version of Windows Phone and basically allow the developer to integrate into the operating system.  For example, there is a ‘Task’ to make a phone call or to compose an email.  I like to define Launchers & Choosers as follows

  1. Launchers – ‘Just Launch it and Forget it’ – Basically, you launch something out the the OS, possibly passing some parameters and hand control over to the operating system.  Don’t expect the user to always come to your application and at this point you will be tombstoned or go into dormant state.  For example, you launch a phone call, the user might hit the start button, and go to another application and never return to your app until it’s needed again
  2. Choosers – this lets you pull information from the operating system in a way that keeps the users data secure and private.  For example, you can ask the user to select a contact and it will return contact information.

With Windows Phone Mango tools out, there are some new Launchers and Choosers that can be of use to developers.  You will find all of them un der the Microsoft.Phone.Tasks namespace on MSDN.  I’ll just go through a summary of the new ones for Mango.

The Launcher Tasks

As developers we did not really get that many new launchers but the ones we got I think will be useful if you are creating mapping applications.

image

The class names are pretty self explanatory but essentially the three do the following

  1. BingMapsDirectionsTask – Will show directions for using the Maps application  
  2. BingMapsTask – will start the Maps application at the defined center point and if a search term is passed in it will add pins on the map that match the search term.

There is also a LabeledMapLocation class that is used with the BingMapsDirectionsTask that is basically a latitude/longitude with a string label

image

And using these are straight forward.  To use the BingMapsDirectionsTask you can use the following code

BingMapsDirectionsTask task = new BingMapsDirectionsTask()
{
    Start = new LabeledMapLocation("Current Position", new System.Device.Location.GeoCoordinate(43.65365522976227, -79.39292348921275)),
    End = new LabeledMapLocation("CN Tower", new System.Device.Location.GeoCoordinate(43.642600285590795, -79.38728012144566)),
};
task.Show();

which will result in the following in the Maps application using the emulator

image

BingMapsTask is just as easy

BingMapsTask task = new BingMapsTask()
{
     Center = new System.Device.Location.GeoCoordinate( 43, -79),
     SearchTerm = "CN Tower",
     ZoomLevel = 15
};
task.Show();

And results in

image

 

The Chooser Tasks

In Windows Phone Mango, we have four new chooser tasks.  Remember, choosers will return something back to us via a Completed event.

  1. AddressChooserTask – allows you to get the address of a contact chosen by the user
  2. SaveContactTask – allows you to initiate a save contact for the user to complete
  3. GameInviteTask – allows you to show the game invite screen to allow user to invite someone else to a multiplayer game session
  4. SaveRingtoneTask – allows you to initiate a save ring tone for the user to complete

I’ll do a quick example on saving a contact.  Essentially you have to create a new SaveContactTask, fill in some properties and call the show event.  The possible properties are

image

and the sample code to save is as follows

SaveContactTask task = new SaveContactTask()
{
    Company = "RedBit",
    FirstName = "Mark",
    HomeAddressCity = "Toronto",
    HomeAddressCountry = "Canada",
    HomeAddressState = "Ontario",
    HomeAddressStreet = "123 Any Street",
    HomeAddressZipCode = "75038",
    HomePhone = "416-123-4567",
    JobTitle = "Not Sure :)",
    LastName = "Arteaga",
};
task.Completed += new EventHandler<SaveContactResult>(task_Completed);
task.Show();

and our completed event handler is as follows

void task_Completed(object sender, SaveContactResult e)
{
    if (e.TaskResult != TaskResult.OK)
        MessageBox.Show("Is there a reason you didn’t save!");
    else
        MessageBox.Show("Done!");
}

which results in

image

and when the user is done, because we wired up the Completed event we will get the appropriate message if the user saved the contact or not.

The Share Tasks

You are probably wondering what the heck is a ‘Share Task’.  Well this is essentially a Launcher but it’s new to Mango and allows you to share the user’s status (ie Facebook status updates) or share a link.

  1. ShareStatusTask – allows user to share a status message on social network of choice
  2. ShareLinkTask – essentially same as status but will share a link on social network of choice

and the object model looks like this

image

Unfortunately this doesn’t work in the emulator but basically what happens on a device is a “Post Message” page pops up, user can select which social network they want to post to and click send.  They do have to option of modifying the post. 

So there you have it, some of the new Launchers & Choosers available in Mango.  I think they are useful and already have plans to integrate into some of our apps and customer apps.

Enjoy!


Thursday, June 30, 2011 4:34:33 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Windows Phone Multitasking–Fast Application Switching#

I recently wrote about the updated story on Windows Phone and Multitasking.  Yes, Windows Phone does multitask and gives developers a few options to get things done which are

  1. Background Audio
  2. Background File Transfers
  3. Fast Application Switching
  4. Scheduled Notifications
  5. Scheduled Tasks

I have already covered Scheduled Notifications on Windows Phone.  In this article, I’ll cover Fast Application Switching or FAS. FAS essentially allows a user to quickly switch applications and not see a delay in switching apps or the ‘resuming …’ screen. When a user navigates away from your application, it will be put in a ‘dormant’ state but the application will still be held in memory. Be aware that even though you are in a dormant state, your threads, timers, web connections will stop running so essentially you can’t run any background threads while dormant.  This image gives a good visual indication of what is happening

image

 

Now, the great thing is you really don’t have to do anything to implement this, as it’s automatically there if you are compiling for Mango.  If your application is compiled for Windows Phone RTM or Nodo and is in Marketplace, you will have to re-compile to get Fast Application Switching.  ‘Legacy’ apps will not get the ‘dormant’ state and will go straight to tombstoned as seen in this image

image

With FAS, as a develoepr you have to be aware that you may still get tombstoned if the device is running low on memory and the OS will tombstone the oldest app. When coming back into the Activated state, you might want to know if you have been tombstoned or not.  This is pretty easy to find out using the ActivatedEventArgs.IsApplicaitonInstancePreserved as follows

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (e.IsApplicationInstancePreserved)
    {
        //We were dormant
    }
    else
    {
        //we were tombstoned
    }
}

As usual not overly complex, and that’s a good thing!  If you want more details on getting ready for Fast Application Switching make sure you spend the time to watch the MIX11 session.  If you are still unsure or unfamiliar with Tombstoning, read over the Execution Model Overview for Windows Phone on MSDN and play around with Visual Studio writing code.

Make sure you are prepared for this, as it will make a far better user experience for your app than the ‘resuming …’ screen!


Thursday, June 30, 2011 2:42:24 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Augmented Reality and Windows Phone 7 Part 2#

A few months ago I wrote about augmented reality on Windows Phone 7 and how the possibilities are there as the platform supports it but it’s all hidden away to third party developers. 

Now that blog post was back on August 24 2010 less than 12 months ago.  Now with Windows Phone Mango, Augmented Reality scenario on Windows Phone is now a “reality”.  Kudos goes out to the Windows Phone team for getting this out in less than 12month! It was already there but my guess is it wasn’t tested enough for general use!

How Do I Use It!

Pre-Mango, we only had access to the CameraCaptureTask which would go ‘outside’ of our application and return us a back picture stream that the user took.  Not the most ideal scenario from a developers point of view but got the job done.

With Mango APIs we now have direct access to the camera and able to stream directly onto a page. You also have the ability take pictures and have various events to tell you what the user is doing, for example CameraButtons.ShutterKeyPressed which tells you when the camera hardware button was pressed.

Now I’m not going to go through how to implement augmented reality on Windows Phone as there is a good sample on MSDN on creating an Augmented Reality app on Windows Phone in combination using the Motion Sensor APIs and camera stream.  I will go through the APIs that allow you to use the camera stream.

First thing, create a new standard Windows Phone Application project

image

To add a video camera stream to your page is quite easy.  First thing add a VideoBrush as the Background to the Grid named ContentPanel in MainPage.xaml.  It should look something like this.

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Grid.Background>
        <VideoBrush x:Name="video" />
    </Grid.Background>
</Grid>

Be aware that the VideoBrush is new to Mango so you won’t be able to use this pre-Mango.  Here is the object model for video brush. 

image

Note, that there is a CameraVideoBrushExtensions class.  Again this is Mango only, and this has a single method called SetSource() which allows you to add a video stream to the VideoBrush. 

Now, to add the stream you create a PhotoCamera  object and call the VideoBrush.SetSource method with the PhotoCamera object as the parameter.  Here is the object model for the PhotoCamera

image

To set the source we create a new global PhotoCamera object  in our MainPage.xaml.cs as follows

Microsoft.Devices.PhotoCamera m_camera;

Then in the constructor of MainPage we add the following

Loaded += (s, e) =>
    {
        m_camera = new Microsoft.Devices.PhotoCamera();
        video.SetSource(m_camera);
    };

Your MainPage.xaml.cs should like like the following

Microsoft.Devices.PhotoCamera m_camera;

// Constructor
public MainPage()
{
    InitializeComponent();

    Loaded += (s, e) =>
        {
            m_camera = new Microsoft.Devices.PhotoCamera();
            video.SetSource(m_camera);
        };
}

Now, when you run the project you will get a stream in the ContentPanel.  You can try this on a real device or on the emulator.  In the emulator you will get a black box moving around a white box.

 

image

Also, the Windows Phone project when first created will automatically add ID_CAP_ISV_CAMERA to your WMAppManifest.xml.  This capability is required if you are using the camera.

And that’s it.  Three lines of XAML and four lines of C#, pretty straight forward to get a camera stream to your app.  Don’t think iPhone or Android devs have it this easy Smile

Feedback, let me know here or via twitter.


Thursday, June 30, 2011 12:46:58 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Windows Phone Multitasking–Scheduled Notifications#

In my previous post I talked about some of the new multitasking features available in Windows Phone Mango.  In this article, I’ll go over Scheduled Notifications in a bit more detail.

You will find all API details in the Microsoft.Phone.Scheduler namespace and the main items we will look at are

A Scheduled Notification is fairly straight forward and essentially will popup a dialog box similar to the calendar reminder in the OS.

There are two types of Scheduled Notifications you can use and these are Alarm and Reminder. This is a good way to integrate with the native OS and not have to build basic pop ups but leverage what is already there.

I’m not going to go through an entire code walk through as there is a good example on MSDN on how to create reminders for Windows Phone. Here is a quick sample on creating a reminder

//Create a reminder
Reminder myReminder = new Reminder("buy milk");
myReminder.Title = "Buy Milk";
myReminder.Content = "Don't forget to buy milk!";
myReminder.BeginTime = DateTime.Now.AddSeconds(10);
myReminder.ExpirationTime = DateTime.Now.AddSeconds(15);
myReminder.RecurrenceType = RecurrenceInterval.None;
myReminder.NavigationUri = new Uri("/MainPage.xaml?fromReminder=1", UriKind.Relative);

//Add the reminder to the ScheduledActionService
ScheduledActionService.Add(myReminder);

Running this code on the emulator will result in the following

image_thumb[2]

Not overly complex but a few key things to note

  • You can specify a NavigationUri which will be used if the user launches your app from the reminder. This way you know if you came from the reminder and can show the specific reminder that was clicked
  • Don’t try to add a reminder with the same name, you will get an exception saying that the reminder already exists

Creating an Alarm is almost the same as creating a Reminder with a few slight differences.

//Create an alarm Alarm alarm = new Alarm("Test Alarm"); alarm.Title = "My Alarm Title"; alarm.Content = "My Test alarm"; alarm.BeginTime = DateTime.Now.AddSeconds(10); alarm.ExpirationTime = DateTime.Now.AddSeconds(15); alarm.RecurrenceType = RecurrenceInterval.None; alarm.Sound = new Uri("");

//Add the reminder to the ScheduledActionService
ScheduledActionService.Add(myReminder);

Again, pretty straight forward but a few key things to note with alarms are

  • A user cannot click from the alarm to your application so you have no NavigationUri property
  • You can specify a custom sound to play using the Sound property but the sound file must be included in your XAP and cannot be played from isolated storage.

Scheduled notifications I think will be useful in some application scenarios and it’s great that we as developers can offset some of the ‘reminder code’ to the API/OS to handle for us.  This is just one of the ways Windows Phone now multitasks and I’ll follow up with the others in upcoming posts.


Tuesday, June 28, 2011 3:26:44 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

All content © 2012, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts