Ejemplo n.º 1
0
        private async void onQRCodeConnectClicked(object sender, EventArgs e)
        {
            var scanner    = new ZXing.Mobile.MobileBarcodeScanner();
            var scanResult = await scanner.Scan();

            if (scanResult != null && scanResult.Text != "")
            {
                var              connectInfo     = Connection.DecodeBluetoothConnection(scanResult.Text);
                Guid             guid            = connectInfo.Guid;
                IBluetoothDevice bluetoothDevice = DependencyService.Get <IBluetoothManager>().GetBluetoothDevice(connectInfo.DeviceAddress);


                IConnectionManager       connectionManager = DependencyService.Get <IConnectionManager>();
                IClientConnection        currentConnection = connectionManager.ControllerConnection as IClientConnection;
                ConnectionEstablishState connectState      = ConnectionEstablishState.Failed;
                IClientConnection        connection        = DependencyService.Get <IBluetoothManager>().CreateRfcommClientConnection(bluetoothDevice, guid);
                if (connectionManager.ControllerConnection != null)
                {
                    bool result = await DisplayAlert("Connect", "Stop Current Connection ?", "Yes", "No");

                    if (result)
                    {
                        if (currentConnection.ConnectionEstablishState == ConnectionEstablishState.Connecting)
                        {
                            currentConnection.AbortConnecting();
                        }
                    }
                }
                connectionManager.ControllerConnection = connection;
                connectState = await connection.ConnectAsync();
            }
        }
Ejemplo n.º 2
0
        private async void onConnectClicked(object sender, EventArgs e)
        {
            if (_SelectedGuid == null)
            {
                Debug.WriteLine("NO UUID SELECTED");
                return;
            }
            IConnectionManager       connectionManager = DependencyService.Get <IConnectionManager>();
            IClientConnection        currentConnection = connectionManager.ControllerConnection as IClientConnection;
            ConnectionEstablishState connectState      = ConnectionEstablishState.Failed;
            IClientConnection        connection        = DependencyService.Get <IManagerManager>().BluetoothManager.CreateRfcommClientConnection(_BluetoothDevice, (Guid)_SelectedGuid);

            if (connectionManager.ControllerConnection != null)
            {
                bool result = await DisplayAlert("Connect", "Stop Current Connection ?", "Yes", "No");

                if (result)
                {
                    if (currentConnection.ConnectionEstablishState == ConnectionEstablishState.Connecting)
                    {
                        currentConnection.AbortConnecting();
                    }
                }
            }
            connectionManager.ControllerConnection = connection;
            connectState = await connection.ConnectAsync();

            if (connectState == ConnectionEstablishState.Succeeded)
            {
            }
        }