Exemplo n.º 1
0
        public static void Disconnect()
        {
            try
            {
                myConnection.thisDevice.Dispose();

                myConnection.thisSocket.OutputStream.WriteByte(187);
                myConnection.thisSocket.OutputStream.Close();

                myConnection.thisSocket.Close();

                myConnection = new BluetoothConnection();
                _socket      = null;
            }
            catch { }
        }
Exemplo n.º 2
0
        public static bool Connect()
        {
            myConnection            = new BluetoothConnection();
            myConnection.thisSocket = null;
            _socket = null;

            myConnection.getAdapter();
            myConnection.thisAdapter.StartDiscovery();

            try
            {
                myConnection.getDevice();
                myConnection.thisDevice.SetPairingConfirmation(false);
                myConnection.thisDevice.SetPairingConfirmation(true);
                myConnection.thisDevice.CreateBond();
            }
            catch (Exception deviceEX)
            {
                Android.Util.Log.Info("Conection", deviceEX.ToString());
            }

            myConnection.thisAdapter.CancelDiscovery();
            _socket = myConnection.thisDevice.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
            myConnection.thisSocket = _socket;

            try
            {
                myConnection.thisSocket.Connect();
                return(true);
            }
            catch (Exception CloseEX)
            {
                Android.Util.Log.Info("Close_EX", CloseEX.ToString());
                return(false);
            }
        }