UWP application development environment: 1. Desktop 2.windows 10 Pro 3. vs2017 15.6 4. A plug-in wireless network card
When I use wifi direct technology to connect directly to the Android system, the connection is unstable 1.The "hs" encountered an error while applying power or reading the device configuration. This may be caused by a failure of your hardware or by poor connection. (Exception from HRESULT: 0x80070288) 2. No element found The above two mistakes frequently appear. Ask experienced people to help us. Thank you. The code is as follows:
private async void ConnectionDevice()
{
try
{
if (directDevice != null)
{
directDevice.Dispose();
directDevice = null;
}
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = "设备连接中...";
});
//
WiFiDirectConnectionParameters connectionParameters = new WiFiDirectConnectionParameters();
connectionParameters.PreferenceOrderedConfigurationMethods.Add(WiFiDirectConfigurationMethod.PushButton);
//connectionParameters.PreferredPairingProcedure = WiFiDirectPairingProcedure.GroupOwnerNegotiation;
directDevice = await WiFiDirectDevice.FromIdAsync(_deviceViewModel.DeviceId);
directDevice.ConnectionStatusChanged += DirectDevice_ConnectionStatusChanged;
if (directDevice != null)
{
var EndpointPairs = directDevice.GetConnectionEndpointPairs();
//创建SOCKET连接监听
StreamSocketListener socketListener = new StreamSocketListener();
await socketListener.BindEndpointAsync(EndpointPairs[0].LocalHostName, "9568");
//连接监听事件
socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = "设备连成功";
});
}
}
catch (Exception ex)
{
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = ex.Message;
});
ConnectionDevice();
}
}
i don't know if you solved it or not but i think this error from the Capabilities, make sure that you have this Capabilities:
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<DeviceCapability Name="proximity" />
User contributions licensed under CC BY-SA 3.0