I am trying to listen connectionRequested listener,
private WiFiDirectConnectionListener _listener;
...
_listener.ConnectionRequested += ConnectionRequestedAsync;
Here is the listener callback,
private async void ConnectionRequestedAsync(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs args)
{
WiFiDirectConnectionRequest request = args.GetConnectionRequest();
if (request != null)
{
try
{
WiFiDirectDevice _device = await WiFiDirectDevice.FromIdAsync(request.DeviceInformation.Id);
...
}
catch (Exception e)
{
Debug.WriteLine(string.Format("Exception::\"{0}\"", e.Message));
}
}
}
Exception found in log (for call WiFiDirectDevice.FromIdAsync
),
Exception::"Exception from HRESULT: 0x80640012"
Any Idea what can be the cause?
Below code worked for me,
try
{
// IMPORTANT: FromIdAsync needs to be called from the UI thread
if (Application.Current.Dispatcher.CheckAccess())
{
_wfdDevice = await WiFiDirectDevice.FromIdAsync(deviceID);
}
else
{
await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(async () =>
{
_wfdDevice = await WiFiDirectDevice.FromIdAsync(deviceID);
}));
}
}
catch (Exception ex)
{
Logger.E($"Exception in FromIdAsync: {ex.Message}, StackTrace: {ex.StackTrace}\n\r");
}