简体   繁体   中英

How to handle calls in Windows Phone 8 application

My app uses a timer that vibrates the device. Now I want to stop this timer when the call is received, otherwise the device goes on vibrating during the call also, and start it back again when the call ends. I tried to handle the events Obscured and Unobscured

PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;

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

but this is not working. These events did not occur when the call was received. How should i handle this?

In App.xaml.cs, there are two methods as seen below. The first is triggered when the application is navigated to and the second is triggered when you navigate from the app (eg when you receive a call).

// 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      
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM