示例#1
0
 protected override void OnResume()
 {
     base.OnResume();
     if (chatService != null)
     {
         if (chatService.GetState() == BluetoothChatService.STATE_NONE)
         {
             chatService.Start();
         }
     }
 }
示例#2
0
            public override void Run()
            {
                Log.Info(TAG, "BEGIN mConnectedThread");
                byte[] buffer;// = new byte[1024];
                int    bytes;

                // Keep listening to the InputStream while connected
                while (service.GetState() == STATE_CONNECTED)
                {
                    buffer = new byte[1024];
                    try
                    {
                        // Read from the InputStream
                        bytes = inStream.Read(buffer, 0, buffer.Length);

                        // Send the obtained bytes to the UI Activity
                        service.handler
                        .ObtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer)
                        .SendToTarget();
                    }
                    catch (Java.IO.IOException e)
                    {
                        Log.Error(TAG, "disconnected", e);
                        service.ConnectionLost();
                        break;
                    }
                }
            }
示例#3
0
            public override void Run()
            {
                Name = $"AcceptThread_{socketType}";
                BluetoothSocket socket = null;

                while (service.GetState() != STATE_CONNECTED)
                {
                    try
                    {
                        socket = serverSocket.Accept();
                    }
                    catch (Java.IO.IOException e)
                    {
                        Log.Error(TAG, "accept() failed", e);
                        break;
                    }

                    if (socket != null)
                    {
                        lock (this)
                        {
                            switch (service.GetState())
                            {
                            case STATE_LISTEN:
                            case STATE_CONNECTING:
                                // Situation normal. Start the connected thread.
                                service.Connected(socket, socket.RemoteDevice, socketType);
                                break;

                            case STATE_NONE:
                            case STATE_CONNECTED:
                                try
                                {
                                    socket.Close();
                                }
                                catch (Java.IO.IOException e)
                                {
                                    Log.Error(TAG, "Could not close unwanted socket", e);
                                }
                                break;
                            }
                        }
                    }
                }
            }
示例#4
0
 public bool IsOnBluetooth()
 {
     if (chatService == null || chatService.GetState() != BluetoothChatService.STATE_CONNECTED)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }