gpt4 book ai didi

android - 列出连接的蓝牙设备?

转载 作者:IT老高 更新时间:2023-10-28 23:25:26 30 4
gpt4 key购买 nike

如何在安卓上列出所有连接的蓝牙设备?

谢谢!

最佳答案

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);
}
};

关于android - 列出连接的蓝牙设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3932228/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com