コード例 #1
0
        private void Connect_Click(object sender, EventArgs e)
        {
            try
            {
                myConnection = new BluetoothConnection();

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

                myConnection.getDevice();
                //myConnection.thisDevice.SetPairingConfirmation(false);
                //myConnection.thisDevice.SetPairingConfirmation(true);
                myConnection.thisDevice.CreateBond();

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

                myConnection.thisSocket.Connect();

                Message("Connected!");
                Connect.Enabled = false;
            }
            catch (Exception ex)
            {
                Message("Connection Error");
            }
        }
コード例 #2
0
        public void Connect()
        {
            if (Connected || _socket != null)
            {
                return;
            }
            try
            {
                Connection = new BluetoothConnection();

                Connection.getAdapter();
                Connection.thisAdapter.StartDiscovery();

                Connection.getDevice();
                //myConnection.thisDevice.SetPairingConfirmation(false);
                //myConnection.thisDevice.SetPairingConfirmation(true);
                Connection.thisDevice.CreateBond();

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

                Connection.thisSocket.Connect();
                Connected = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }