Exemple #1
0
        // Initialize advertizing and if Receiver handle connetion request
        public void Init(bool IsReceiver)
        {
            // Create an instance of Wifi Direct advertiser
            if (publisher == null)
            {
                publisher = new WiFiDirectAdvertisementPublisher();
            }

            // Listen to connection request if receiver
            if (IsReceiver)
            {
                WiFiDirectConnectionListener listener = new WiFiDirectConnectionListener();
                listener.ConnectionRequested += (WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs connectionEventArgs) =>
                {
                    // Because HandleConnectionRequestAsync generates a connection dialog window It request UI Thread
                    WiFiDirectConnectionRequest connectionRequest = connectionEventArgs.GetConnectionRequest();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        // Request a connection to given device
                        var id = connectionRequest.DeviceInformation.Id;
                        //connectionRequest.Dispose();
                        await WifiDirectHandler.ConnectAsync(id, IsReceiver);
                    });
                };
            }
            // Start advertisement with Intensive parameter so that WifiDirect stay enabled even if app is in background
            publisher.Advertisement.ListenStateDiscoverability = WiFiDirectAdvertisementListenStateDiscoverability.Intensive;
            publisher.Start();
        }
Exemple #2
0
 public async void Connect(string DeviceID, bool IsReceiver)
 {
     await WifiDirectHandler.ConnectAsync(DeviceID, IsReceiver);
 }
Exemple #3
0
 public void FindWFDDevices()
 {
     WifiDirectHandler.GetDevices();
 }