Code example for BluetoothServerSocket

Methods: accept

0
    public int onStartCommand(Intent intent, int flags, int startId) {
        new Thread(new Runnable() {
            @Override 
            public void run() { 
                try { 
                    BluetoothSocket mSocket = mServerSocket.accept();
                    InputStream is = mSocket.getInputStream();
                    byte[] buffer = new byte[1024];
                    int bytes;
                    bytes = is.read(buffer);
 
                    String message = new String(buffer, 0, bytes);
                    Log.d(TAG, "received message: " + message);
                } 
                catch (IOException e) {
                    Log.d(TAG, e.getMessage());
                } 
            } 
        }).start();
 
        return super.onStartCommand(intent, flags, startId);