Added code based on Android sample BluetoothChat.