如何获取正在使用的蓝牙名称?

发布于 2022-09-11 22:18:28 字数 1210 浏览 28 评论 0

现在我的手机连接了两个蓝牙耳机,其中一个正在使用中,另一个正处于连接状态。如何获取正在使用的蓝牙耳机的名称?目前,我已经知道如何获得蓝牙耳机的名称,但我无法得到哪一个正在使用。有没有可用的接口?

// 这时获取所有蓝牙设备的方法
mAdapter = BluetoothAdapter.getDefaultAdapter();
mAdapter.getProfileProxy(ctx, new BluetoothProfile.ServiceListener() {

            @Override
            public void onServiceDisconnected(int profile) {
                LogUtil.e(TAG, "onServiceDisconnected");
                callback.onFail();
            }

            @Override
            public void onServiceConnected(int profile, BluetoothProfile proxy) {
                LogUtil.e(TAG, "onServiceConnected");
                List<BluetoothDevice> mDevices = proxy.getConnectedDevices();
                if (mDevices != null && mDevices.size() > 0) {
                    LogUtil.e(TAG, "connected devices not null");
                    for (BluetoothDevice device : mDevices) {
                        if (device != null) {
                            mDeviceName = device.getName();
                            callback.onSuccess(mDeviceName);
                        }
                    }
                }
                callback.onFail();
            }
        }, mProfileType);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮子 2022-09-18 22:18:28

已经找到解决方法,记录在我的专栏里了,详见https://segmentfault.com/a/11...

看春风乍起 2022-09-18 22:18:28

BluetoothAdapter.getDefaultAdapter()

我感觉默认的应该就是

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文