2015-01-13 105 views
-1

在android中,我试图获取蓝牙配对设备列表,然后检查是否有耳机麦克风。检查蓝牙设备是否有麦克风Android

是否有可能在android中找到它?

Set pairedDevices = bluetoothAdapter.getBondedDevices();

 for (BluetoothDevice device : pairedDevices) { 

      BluetoothClass bluetoothClass = device.getBluetoothClass(); 



      if (bluetoothClass != null) { 
       int deviceClass = bluetoothClass.getDeviceClass(); 



       if (deviceClass == Device.AUDIO_VIDEO_WEARABLE_HEADSET 
         || deviceClass == Device.AUDIO_VIDEO_CAR_AUDIO 
         || deviceClass == Device.AUDIO_VIDEO_HANDSFREE 
         || deviceClass == Device.AUDIO_VIDEO_UNCATEGORIZED 


         ) { 
          } 
         } 
        } 

如何从设备类知道它是否有能力话筒,或者用户可以从设备说话,如果返回的设备类Device.AUDIO_VIDEO_WEARABLE_HEADSET?

回答

0

您可以使用检查蓝牙设备的类:

private void getDeviceClass(BluetoothDevice device) { 
    int btClass = device.getBluetoothClass().getDeviceClass(); 
    // check your device class; class constants are listed in the Reference link 
    // AUDIO_VIDEO_MICROPHONE, AUDIO_VIDEO_HANDSFREE, 
    // or even PHONE_* may match your requirements 
} 

参考:BluetoothClass.Device

+0

香港专业教育学院编辑我原来的问题,问题是,在与支持蓝牙的Bose音频扬声器,设备类返回Device.AUDIO_VIDEO_WEARABLE_HEADSET.But bose音频扬声器没有麦克风功能。 我正在开发一个拨号应用程序,如果设备没有麦克风功能,则不应该将音频路由到扬声器。 –

+0

这个[app](https://play.google.com/store/apps/details?id=com.webalis.bluetoothMicTest&hl=en)会记录一小段音频,并检查音频是否有音量。也许你可以做类似的逻辑。 – Raptor

+0

不认为是一个很好的解决方案,在我的拨号应用程序中,当通话连接时,生病需要决定将音频路由到哪里,并将头戴式麦克风输入或设备麦克风输入。 在这种情况下,用户可能不会说话,音频也不会有任何音量。 确定应该有mi的能力,因为手机的默认拨号器应用程序会这样做,当耳机没有麦克风时,它不会将音频路由到耳机。 –