/// <summary>
        ///
        /// </summary>
        /// <param name="ConnectedAction">连接成功</param>
        /// <param name="ConnectingAction">连接中</param>
        /// <param name="ConnFailedAction">断开链接(用户UI提示)</param>
        /// <returns></returns>
        public int Init(Action <string, string> ConnectedAction, Action <string> ConnectingAction, Action <string> ConnFailedAction)
        {
            //断开重连
            Action <string> connLost = (mess) =>
            {
                if (GetState() == 1)
                {
                    if (!string.IsNullOrEmpty(address))
                    {
                        Log.Debug(TAG, mess);
                        Stop();
                        System.Threading.Thread.Sleep(2000);
                        Connect(address);
                    }
                }
            };
            int err = 0;

            Stop();
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
            if (bluetoothAdapter == null)
            {
                err = (int)PrintError.NotSupportBluetooth;
                return(err);
            }
            else
            {
                chatService = new BluetoothService(new MyHandler(this, ConnectedAction, ConnectingAction, ConnFailedAction, connLost));
                isopen      = true;
                err         = 1;
                return(err);
            }
        }
Exemple #2
0
            public AcceptThread(BluetoothService service)
            {
                _service = service;
                BluetoothServerSocket tmp = null;

                // Create a new listening server socket
                try {
                    tmp = _service._adapter.ListenUsingRfcommWithServiceRecord(NAME, MY_UUID);
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
Exemple #3
0
            public ConnectThread(BluetoothDevice device, BluetoothService service)
            {
                mmDevice = device;
                _service = service;
                BluetoothSocket tmp = null;

                // Get a BluetoothSocket for a connection with the
                // given BluetoothDevice
                try {
                    tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID);
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "create() failed", e);
                }
                mmSocket = tmp;
            }
Exemple #4
0
 public bool Init(out int err, Action <string, string> ConnectedAction, Action <string> ConnectingAction, Action <string> ConnFailedAction)
 {
     err = 0;
     bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
     if (bluetoothAdapter == null)
     {
         err = 2;
         return(false);
     }
     else
     {
         chatService = new BluetoothService(new MyHandler(this, ConnectedAction, ConnectingAction, ConnFailedAction));
         return(true);
     }
 }
        public int Init(Action <string, string> ConnectedAction, Action <string> ConnectingAction, Action <string> ConnFailedAction)
        {
            int err = 0;

            Stop();
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
            if (bluetoothAdapter == null)
            {
                err = (int)PrintError.NotSupportBluetooth;
                return(err);
            }
            else
            {
                chatService = new BluetoothService(new MyHandler(this, ConnectedAction, ConnectingAction, ConnFailedAction));
                isopen      = true;
                err         = 1;
                return(err);
            }
        }
Exemple #6
0
            public ConnectedThread(BluetoothSocket socket, BluetoothService service)
            {
                Log.Debug(TAG, "create ConnectedThread: ");
                mmSocket = socket;
                _service = service;
                Stream tmpIn  = null;
                Stream tmpOut = null;

                // Get the BluetoothSocket input and output streams
                try {
                    tmpIn  = socket.InputStream;
                    tmpOut = socket.OutputStream;
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "temp sockets not created", e);
                }



                mmInStream  = tmpIn;
                mmOutStream = tmpOut;
            }