首页> C#>如何处理Windows Phone 8应用程序中的呼叫

  

我的应用程序使用计时器来振动设备.现在,我想在接听电话时停止此计时器,否则设备也会在通话期间继续振动,并在通话结束时重新启动.我试图处理模糊和不模糊的事件

PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;

if (rootFrame != null)
{
    rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
    rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}

但这不起作用.收到呼叫时未发生这些事件.我该如何处理?

解决方法:

在App.xaml.cs中,有两种方法,如下所示.第一个在应用程序导航至时触发,第二个在您从应用程序导航时触发(例如,在接到电话时).

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    //start timer here
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    //stop timer here      
}
相关文章