Detect if Windows Phone 7 is connected to desktop Zune software

大兔子大兔子 提交于 2019-12-01 08:47:58

Gabor Dolhai has a full blog post on Zune Detection and Network Awareness, which uses a combiantion of NetworkInterfaceType detection and the NetworkAddressChangeed event.

Testing for NetworkInterfaceType being Ethernet gets you close, but not quite there - as this isn't sensitive to the status of Zune vs WPConnect for the connection. Also, reading NetworkInterfaceType also can prove to be less than a walk in the park.

Handling the resulting exception seems to be the reliable method, however the exception does appear to vary between some media APIs, so keep an eye out for that.

After reviewing the answers from Mike and Derek, I Decided to go with a simple timer to detect when the CameraCaptureTask returns faster than expected. This is done by adding the following right before the call to start the capture task:

State["CameraCaptureStart"] = DateTime.Now;//Save start time to detect fast cancel from zune software

Then when the capture finishes you can detect if it returned too fast:

//Detect if task returned too fast
if (State.ContainsKey("CameraCaptureStart"))
{
    DateTime dtStart = (DateTime)State["CameraCaptureStart"];
    TimeSpan ts = DateTime.Now - dtStart;
    if (ts < TimeSpan.FromSeconds(3))
    {
        MessageBox.Show("Error: Camera does not work while phone is connected to the Zune software.");
    }
}

In my testing the fastest I could load the camera, take a picure, and push the accept button was around 5-6 seconds, where as the Zune software would automatic cancel and return in around 2.5 seconds.

This approach is simple and works well for my situation, however you should be aware that the error message will also be displayed if the user presses the back button before the 3 second timeout has elapsed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!