Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

bluetooth chat example android server

Thread {
            bluetoothAdapter?.startDiscovery()
            val server : BluetoothServerSocket? = bluetoothAdapter?.listenUsingRfcommWithServiceRecord("Bluetooth", uuid)
            var loop = true
            while (loop) {
                Log.d("Server", "Printing")
                val bluetoothSocket: BluetoothSocket? = try {
                    server?.accept()
                } catch (e: IOException) {
                    Log.e("ServerSocket", "Socket's accept() failed", e)
                    e.printStackTrace()
                    null
                }
                bluetoothSocket?.let {
                    binder.socketConnectedCallback?.onSocketConnected(it)
                }
                server?.close()
                loop = false
            }
        }.start()
Source by davidadeyyinka.medium.com #
 
PREVIOUS NEXT
Tagged: #bluetooth #chat #android #server
ADD COMMENT
Topic
Name
3+8 =