마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

블루투스 데이터 수신 byte

0 추천
블루투스로 들어오는 데이터가 1234567890 이면
1
234567890 
이렇게 나눠들어오는걸  아래와 같이하니 한 문장으로 붙어서 들어왔습니다.
그런데 최고가 10byte더라구요. 1234567890123456을보내면
1234567890
123456 이렇게 나눠서 또 들어옶니다. 이방법을 해결할 방법이 없을까요? 
public void run() {
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;
 
            int check_bytes = 0;
            byte[] buffer_b = new byte[1024];
            
            // Keep listening to the InputStream while connected
            while (true) {
                try {
                    // Read from the InputStream
                    bytes = mmInStream.read(buffer);
                    if(bytes == 1)
                    {
                    //buffer_b 에 buffer 를 1byte copy
                        System.arraycopy(buffer, 0, buffer_b, 0, 1);
                    check_bytes = 1;
                    }
                    else
                    {
                    if(check_bytes==1)
                    {
                    //buffer_b에 buffer를 붙이고 bytes+1 해서 보냄
                    System.arraycopy(buffer, 0, buffer_b, 1, bytes); 
                            mHandler.obtainMessage(Sensor_mode.MESSAGE_READ, bytes+1, -1, buffer_b)
                            .sendToTarget();
                    check_bytes=0;
                   
                    }else
                    {
                    // Send the obtained bytes to the UI Activity
                            mHandler.obtainMessage(Sensor_mode.MESSAGE_READ, bytes, -1, buffer)
                                    .sendToTarget();                    
                    }
                    }
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    break;
                }
            }
        }
와따까따뿌따 (180 포인트) 님이 2014년 6월 26일 질문

1개의 답변

0 추천
꼭 다 합쳐서 보내야 하나요? 객체를 byte화 하려 전송해보세요.
인연 (31,880 포인트) 님이 2014년 6월 27일 답변
...