BluetoothChat doesn't work

Posted by jes on Stack Overflow See other posts from Stack Overflow or by jes
Published on 2010-06-17T15:48:51Z Indexed on 2010/06/17 15:53 UTC
Read the original article Hit count: 164

Filed under:
|

Hello I want to make conversation between android devices. I use BluetoothChat to do this but it doesn't work I can't read correctly data from another device.

Conversation is :

Me: privet

Device: p Device: rivet

Can you help me?

private class ConnectedThread extends Thread {

    private final InputStream mmInStream;
    private final OutputStream mmOutStream;

    public ConnectedThread(BluetoothSocket socket) {
        Log.d(TAG, "create ConnectedThread");
        mmSocket = socket;
        //InputStream tmpIn = null;
        OutputStream tmpOut = null;
        BufferedInputStream tmpIn=null;

        int INPUT_BUFFER_SIZE=32;
        // Get the BluetoothSocket input and output streams
        try {
            //tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
            tmpIn = new BufferedInputStream(socket.getInputStream(),INPUT_BUFFER_SIZE);

        } catch (IOException e) {
            Log.e(TAG, "temp sockets not created", e);
        }

        mmInStream = tmpIn;
        mmOutStream = tmpOut;
    }

    public void run() {
        Log.i(TAG, "BEGIN mConnectedThread");
        byte[] buffer = new byte[1024];
        int bytes;

        // Keep listening to the InputStream while connected
        while (true) {
            try {
                // Read from the InputStream

              bytes = mmInStream.read(buffer);
                // Send the obtained bytes to the UI Activity
                mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
                        .sendToTarget();
            } catch (IOException e) {
                Log.e(TAG, "disconnected", e);
                connectionLost();
                break;
            }
        }
    }

© Stack Overflow or respective owner

Related posts about android

Related posts about bluetooth