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

블루투스 리스너가 있나요?

0 추천
BluetoothProfile.ServiceListener

블루투스 상태를 알수있는 리스너가 있나요?

 

블루투스가 연결이 되었다던지 연결이 끊겼다던지 알수있는 리스너같은게 있을 것 같은데

 

키워드좀 알려주십시오. ㅠㅠ

serviceListener로 구현하니

불러줘야지만 상태확인이 가능하더라고요..

BT가 끊기거나 BT가 연결이되면 바로 알수있는 방법 없나요 ?

 

 

now882002 (3,860 포인트) 님이 2014년 11월 11일 질문
now882002님이 2014년 11월 11일 수정

1개의 답변

+1 추천
 
채택된 답변

블루투스 켜짐/꺼짐 : BluetoothAdapter.ACTION_STATE_CHANGED

기기 연결/해제 : BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED

 

켜짐/꺼짐

int bluetoothState = $intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (bluetoothState == BluetoothAdapter.STATE_OFF)
{
}
else if (bluetoothState == BluetoothAdapter.STATE_ON)
{
}

 

 

연결/해제

else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(action))
{
  BluetoothDevice device = $intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
  if (device == null)
    return;
  
  int bluetoothState = $intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, BluetoothA2dp.STATE_DISCONNECTED);
  if (bluetoothState == BluetoothA2dp.STATE_CONNECTED)
  {
    
  }
  else if (bluetoothState == BluetoothA2dp.STATE_DISCONNECTED)
  {
    
  }
}

 

쎄미 (162,410 포인트) 님이 2014년 11월 11일 답변
now882002님이 2014년 11월 12일 채택됨
...