我可以在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
但在Wondows 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
{
}
}
答案 0 :(得分:1)
在Windows Phone(从7.0到当前版本8.1的所有版本)中,无法以编程方式关闭或打开WiFi。这是因为平台始终将这些设置留在用户的控件中。
您最接近的是以编程方式启动WiFi设置页面,用户可以在其中修改设置:
await Launcher.LaunchUriAsync(new Uri("ms-settings-wifi:"));