Jeff Prosise's Blog

Silverlight for Windows Phone Programming Tip #6

Recently I have heard of a couple of cases in which apps submitted to the Windows Phone Marketplace were rejected because they continued running when an incoming phone call arrived. While the Windows Phone 7 Application Certification Requirements don’t specifically state than an application must pause when a call arrives, it seems that certain actions do trigger increased scrutiny from the certification folks. In one case, the app was rejected because it used the phone’s vibration controller and didn’t stop the vibration when the phone rang.

There is no specific API in Silverlight for Windows Phone for detecting incoming phone calls, but there is a pair of events in the PhoneApplicationFrame class named Obscured and Unobscured. Many developers mistakenly assume that these events are only raised when the screen locks and unlocks. In fact, they’re raised anytime your application is obscured by a piece of the UI shell, including when the phone receives a call. Regardless of whether your app is designed to run under a locked screen, you can use these events to make sure that your app behaves properly when it’s interrupted by a phone call or anything else that brings the shell to the foreground.

A page can register handlers for Obscured and Unobscured events through the application’s RootFrame property. The following code snippet registers handlers for both events and calls VibrateController.Stop when the application is obscured by the shell:

 

(Application.Current as App).RootFrame.Obscured += OnObscured;

(Application.Current as App).RootFrame.Unobscured += OnUnobscured;

  .

  .

  .

void OnObscured(object sender, ObscuredEventArgs e)

{

    VibrateController.Default.Stop();

}

 

void OnUnobscured(object sender, EventArgs e)

{

}

 

The Windows Phone 7 Application Certification Requirements do state that an application “must not delay or prevent the ability of the user to initiate a call, answer an incoming call, or end a call.” If you write an app whose actions could violate that dictum, use Obscured and Unobscured events to devise a fix.

On Feb 11 2011 5:47 AMBy jprosise With 11 Comments

Comments (11)

  1. Thanks for the tip, but actually i need to simulate an incoming call as my application will automatically send sms replies to it and it seems that there is no way to do it on the emulator..

  2. Thank you Thank you Thank you so much.
    Mine is one of those apps which was rejected for the reason that vibration didnot stop on an incoming call and i had tried so many things.
    I shall try this and lets hope it works

  3. Jeff, thanks for the info, however i get the following when trying to add the code to my MainPage.xaml.cs MainPage class...

    System.Windows.Application.Current is a property but is used as a type.

  4. unfortunately although the code now compiles, this is not stopping the vibration controller. My app has been rejected twice now as the incoming phone call does not stop the vibration controller even when i implement the OnObscured event and call VibrateController.Default.Stop.

  5. I used this tip in following scenario.
    I have to stop my animations and reset some element properties like opacity=0, in the OnNavigatedFrom. Interesting OnNavigatedFrom is also called upon going into Obscured mode. So upon resuming, I was losing my animation and the elemets were set to opacity=0 making them invisible.

    So I used the two events to solve those issues.

    Thanks for blogging this.

  6. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I will be subscribing to your feed and I hope you post again soon. Thanks!

Leave a Comment