안드로이드와 아두이노 블루투스 연동을 공부 중인데,
현재 아두이노가 배송 중이라서 안드로이드 끼리 연동 개발 중입니다.
페어링은 현재 성공했고 소캣접속 할 순간인데 계속 에러가 납니다.
mSocket.connect(); 여기가 말썽입니다...
구글이나 네이버, 파이어폭스 등등 온통 다 찾아다녔는데 해결이 나지 않아 질문을 올리게 되었습니다..
며칠째 해결을 못하고 있습니다..ㅠㅠㅠㅠ
처음엔 로그구요 그다음은 소스입니다.. ㅠ-ㅠ 도와주세요 ㅠㅠㅠㅠ
07-31 19:52:53.759: D/BluetoothUtils(28586): isSocketAllowedBySecurityPolicy start : device null
07-31 19:52:53.759: W/BluetoothAdapter(28586): getBluetoothService() called with no BluetoothManagerCallback
07-31 19:52:53.759: D/BluetoothSocket(28586): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[70]}
07-31 19:57:45.559: D/dalvikvm(28586): GC_FOR_ALLOC freed 403K, 9% free 18686K/20400K, paused 24ms, total 35ms
void connectToSelectedDevice(String selectedDeviceName) {
// BluetoothDevice 원격 블루투스 기기를 나타냄.
// mRemoteDevie = getDeviceFromBondedList(selectedDeviceName);
mRemoteDevie = mBluetoothAdapter.getRemoteDevice(selectedDeviceName);
Handler mHandler = new Handler(Looper.getMainLooper());
// java.util.UUID.fromString : 자바에서 중복되지 않는 Unique 키 생성.
ParcelUuid[] uuids = mRemoteDevie.getUuids();
//UUID uuid = java.util.UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try {
//mSocket = mRemoteDevie.createInsecureRfcommSocketToServiceRecord(uuid);
mSocket = mRemoteDevie.createInsecureRfcommSocketToServiceRecord(uuids[0].getUuid());
mHandler.post(new Runnable() {
@Override
public void run(){
try{
mSocket.connect();
//mOutputStream = mSocket.getOutputStream();
// mInputStream = mSocket.getInputStream();
// 데이터 수신 준비.
// beginListenForData();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "블루투스 연결 중 오류가 발생했습니다.", Toast.LENGTH_LONG).show();
}
}
});
} catch (IOException e) {;}
}
꼭 부탁드립니다 ㅠㅠㅠ 작은 실마리라도 주심 감사하겠습니다