我可以以编程方式打开和关闭Windows Phone 8.1的WiFi吗

本文关键字:Phone WiFi Windows 编程 方式打 我可以 | 更新日期: 2023-09-27 18:25:32

我可以在Windows Phone 8.1上以编程方式打开和关闭WiFi吗?

如果是,如何打开/关闭C#上的wifi?

事实上,我已经在另一个平台上做到了:

<DllImport("coredll.dll")> Public Shared Function DevicePowerNotify(ByVal device As String, ByVal state As CEDEVICE_POWER_STATE, ByVal flags As Integer) As Integer  
End Function  
<DllImport("coredll.dll")> Public Shared Function SetDevicePower( _  
ByVal pvDevice As String, _  
ByVal df As Integer, _  
ByVal ds As CEDEVICE_POWER_STATE) As Integer  
End Function  
Public Shared Sub wifi_power_on()  
    Try  
        DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}'cardname", CEDEVICE_POWER_STATE.D0, 1)  
        SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}'cardname", 1, CEDEVICE_POWER_STATE.D0)  
        Application.DoEvents()  
    Catch  
    End Try  
End Sub  
Public Shared Sub wifi_power_off()  
    Try  
        DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}'cardname", CEDEVICE_POWER_STATE.D4, 1)  
        SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}'cardname", 1, CEDEVICE_POWER_STATE.D4)  
        Application.DoEvents()  
    Catch  
    End Try  
End Sub 

但是在WonWindows Phone 8.1中,我不知道这次如何在C#中做同样的事情

恐怕这不是同样的支持?

这就是我在C#中尝试的:

    [DllImport("coredll.dll")]
    public static extern int DevicePowerNotify(string device, CEDEVICE_POWER_STATE state, int flags);
    [DllImport("coredll.dll")]
    public static extern int SetDevicePower(string pvDevice, int df, CEDEVICE_POWER_STATE ds);
    public static void wifi_power_on()
    {
        try
        {
            DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}''cardName", CEDEVICE_POWER_STATE.D0, 1);
            SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}''cardName", 1, CEDEVICE_POWER_STATE.D0);
            Application.DoEvents();
        }
        catch
        {
        }
    }
    public static void wifi_power_off()
    {
        try
        {
            DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}''cardName", CEDEVICE_POWER_STATE.D4, 1);
            SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}''cardName", 1, CEDEVICE_POWER_STATE.D4);
            Application.DoEvents();
        }
        catch
        {
        }
    }

我可以以编程方式打开和关闭Windows Phone 8.1的WiFi吗

在Windows Phone(从7.0到当前8.1的所有版本)中,您无法通过编程关闭或打开WiFi。这是因为平台始终将这些类型的设置交给用户控制。

最接近的方法是以编程方式启动WiFi设置页面,用户可以在其中修改设置:

await Launcher.LaunchUriAsync(new Uri("ms-settings-wifi:"));