블루투스 챗 예제를 응용해서 원격 조작 어플을 구현하려고 하고있습니다.
문제는 이 어플이 직접 조작 방식 / 원격 조작 방식 두 가지를 지원하는데,
메뉴에서 조작 방식을 사용자가 선택하도록 합니다.
기본은 직접 조작 방식이며 메뉴에서 '원격 조작' 메뉴를 선택하여 블루투스 기기로 조작하게 하는 방식입니다.
예제 프로젝트의 "BluetoothChat"을 조금 손봐서 집어넣었는데,
사용자가 "원격 조작" 메뉴 선택시 블루투스 서비스를 시작하도록 메뉴 함수 안에 service 쓰레드 start()를 넣었더니
페어링이 안됩니다...ㅜ
메뉴 부분의 코드는 이렇습니다 ↓↓
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.item1:
Toast.makeText(this, "touch mode", Toast.LENGTH_SHORT).show();
L = false;
return true;
case R.id.item2:
Log.d("BluetoothChat","menu change");
Toast.makeText(this, "recieve mode", Toast.LENGTH_SHORT).show();
L = true;
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 3);
if (mChatService != null) {
// Only if the state is STATE_NONE, do we know that we haven't started already
if (mChatService.getState() == BluetoothChatService.STATE_NONE) {
// Start the Bluetooth chat services
mChatService.start();
}
}
return true;
}
return super.onOptionsItemSelected(item);
}
mChatService.start()를 onResume()에 넣어서
처음 시작부터 블루투스 서비스 쓰레드가 돌아가도록 하면 페어링이 잘 되는데
저렇게 처음에는 시작 안 하고 메뉴 선택 후 부터 시작하려고 하니까
맞은편(리모컨)에서 연결할 수 없다는 메시지만 자꾸 뜨네요ㅜ
로그를 봐도 다른 에러는 없었습니다.