【问题标题】:How to get information about CONNECTED bluetooth device for android?如何获取有关适用于 android 的 CONNECTED 蓝牙设备的信息?
【发布时间】:2022-03-14 09:05:20
【问题描述】:

如果我的 Android 手机已经连接了蓝牙耳机(已配对并连接)。 如何获取有关该特定耳机的信息。

使用getBondedDevices() 方法我得到所有配对设备的列表..我只需要有关已连接设备的信息。

我不能等待广播接收器检查状态,因为我在我的应用程序开始时需要这些信息。所以请建议有什么方法可以在不等待广播的情况下获取此信息。

【问题讨论】:

标签: bluetooth headset


【解决方案1】:

您可以通过 API 11 及更高版本中的 IBluetoothA2dp 接口执行此操作。更多信息在这里:Android connect to a paired bluetooth headset

这里是一个很好的资源,可以查看 API 10 和 11 之间的此接口可用的差异,其中它发生了很大变化。 http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/bluetooth/BluetoothA2dp.java/?v=diff&id2=2.2_r1.1

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    您可以使用耳机配置文件的getConnectedDevices 来获取它所连接的设备。

    【讨论】:

      【解决方案3】:

      检查耳机是否已连接(仅限 ICS):

          public boolean isVoiceConnected()
          {
              boolean retval = true;
              try {
                  retval = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED;
      
              } catch (Exception exc) {
                  // nothing to do
              }
              return retval;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-24
        • 2012-07-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多