我正在为 android 2.2 API Level 8 编程,并且我试图确定当我的应用程序最初启动时当前是否连接了蓝牙耳机。我似乎无法找到解决此问题的方法。
一旦我的应用程序启动并运行,我就可以侦听 BluetoothDevice.ACTION_ACL_CONNECTED 和 BluetoothDevice.ACTION_ACL_DISCONNECTED,如此处所示,这对你很有帮助。但我不知道如何在广播接收器打开之前判断当前是否连接了蓝牙耳机。
我还想出了如何通过以下方式查看设备是否有任何配对设备。
BluetoothAdapter mBluetoothAdapter = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter != null)
{
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() != 0)
{
// the device has paired devices
for (BluetoothDevice device : pairedDevices)
{
Log.i(TAG, "device name: " + device.getName());
Log.i(TAG, "device address: " + device.getAddress());
}
}
else
{
// no paired devices
Log.i(TAG, "no paired devices");
}
}
我希望那里的某个人已经为 API 级别 8 解决了这个问题。我确实意识到在 API 11 中有一些新类,例如 BluetoothProfile和 BluetoothHeadset可能可以在 1 行代码中完成此操作,但我再次我正在尝试在 API 级别 8 中执行此操作
我愿意在这一点上尝试任何事情。
提前致谢
-H