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

안드로이드 Bluetooth 관련 질문입니다.

0 추천

안녕하세요 초보개발자입니다.

 
휴대폰에서 블루투스를 한번 등록하면 페어링 목록에 들어가잖아요..
예를들어 5개의 블루투스를 휴대폰에 연결한 적이 있다면 페어링된 기기에는 5개의 블루투스가 있겠죠..?
페어링된 디바이스들의 정보를 가져오는 것은 쉬운일입니다..
 
하지만 여기서,
안드로이드의 BluetoothAdapter.getBondedDevices(); 메서드가
페어링 된 디바이스 목록들을 리스트형으로 반환해주고 있는데.
 
등록되어있는 Bluetooth Device 리스트가 아닌
등록되어있는 Bluetooth Device 리스트 중에 현재 휴대폰과 연결이 되어있는 bluetooth 기기를 찾고싶습니다.
 
가능합니까?
 
제발 좀 알려주세요 제발..
윤둥이 (4,560 포인트) 님이 2014년 4월 14일 질문

1개의 답변

+1 추천
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.HEADSET 은 마이크도 달린 것,

BluetoothProfile.A2DP는  바꾸면 보통 헤드폰을 검색합니다. 

 

http://susemi99.kr/1348

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