노트북과 스마트폰을 블루투스로 연결해 채팅하는거 연습중인데요
블루투스로 연결한 다음 노트북 서버프로그램으로 숫자 10 이상 입력시 앱에서 파란색글씨로
출력되게끔 하고싶어서 아래와 같이 해봤는데 10이상이 아닐때도 파란색으로 나오고
종종 서버에서 보낸 숫자를 읽어들이지못해 출력을 못하는 경우도 있더라구요
이리저리 코드 바꿔가면서 해보고잇는데 도저히 모르겠습니다 도와주세요
public void showMessage(String strMsg) {
Message msg = Message.obtain(mHandler, 1, strMsg);
mHandler.sendMessage(msg);}
Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
String strMsg = (String) msg.obj;
switch (msg.what) {
case 0:
mTextMsg.setText(strMsg);
break;
case 1:
try {
IntStrMsg = Integer.parseInt(strMsg);
} catch (NumberFormatException nfe) {
if (IntStrMsg > 10) {
mTextMsg.setTextColor(Color.parseColor("#0100FF"));
}
mTextMsg.setText(strMsg);}
break;}}};
public void run() {
byte[] buffer = new byte[1024];
int bytes;
while (true) {
try {
bytes = mmInStream.read(buffer);
String strBuf = new String(buffer, 0, bytes);
showMessage(strBuf);
SystemClock.sleep(1);
} catch (IOException e) {
showMessage("Socket disconneted");
break;}}}
아! 그리고 case 0 일 경우는 위에 message.obtain이 case 1로 잘 보내는지 확인해보고 싶어서 일단 넣어둔건데 message.obtain(mHandler, 1, strMsg) 이라고 해놓으면 case 1로 가는게 맞는거죠?..