Detect if Windows Phone 7 is connected to desktop Zune software

前端 未结 3 1457
别跟我提以往
别跟我提以往 2021-01-14 03:35

I\'ve been working on a Windows Phone 7 app for a few months now and have a collection of useful detection flags that are used to test for things like if the code is running

相关标签:
3条回答
  • 2021-01-14 04:16

    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.

    0 讨论(0)
  • 2021-01-14 04:22

    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.

    0 讨论(0)
  • 2021-01-14 04:32

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

    0 讨论(0)
提交回复
热议问题