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

Bluetooth 상태 받아오기

0 추천
예를들어 이어폰 연결 / 끊김 상태는 Intent 에 action 값이 있어서 BroadcastReceiver로 받아서 즉각 처리할 수 있는데

 

Bluetooth on / off 또는 페어링 등의 상태는 Intent  action값에 없는 것 같더라구요..

Bluetooth 의 상태도 즉각즉각 받아서 처리 할 수 있는 방법이 있을까요?
윤둥이 (4,560 포인트) 님이 2013년 8월 2일 질문

1개의 답변

0 추천

http://susemi99.kr/1348

 

현재 연결된 헤드폰이나 헤드셋의 목록을 알 수 있습니다.

 

public void checkConnected()
{
  // true == headset connected && connected headset is support hands free
  int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET);
  if (state != BluetoothProfile.STATE_CONNECTED)
    return;
 
  try
  {
    BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET);
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }
}
 
private ServiceListener serviceListener = new ServiceListener()
{
  @Override
  public void onServiceDisconnected(int profile)
  {
 
  }
 
  @Override
  public void onServiceConnected(int profile, BluetoothProfile proxy)
  {
    for (BluetoothDevice device : proxy.getConnectedDevices())
    {
      Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = "
          + BluetoothProfile.STATE_CONNECTED + ")");
    }
 
    BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy);
  }
};

 

헤드폰은 노래만 듣는거고, 헤드셋은 마이크가 달려서 전화통화도 되는 겁니다.

BluetoothProfile.A2DP : headphone
BluetoothProfile.HEADSET : headset(핸즈프리 지원)

 

쎄미 (162,410 포인트) 님이 2014년 6월 18일 답변
...