首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在tinyB java特性上没有通知

在tinyB java特性上没有通知
EN

Stack Overflow用户
提问于 2022-08-11 15:20:34
回答 1查看 22关注 0票数 0

我试图将简单设备(AB Shutter3)连接到PC上的java应用程序,但在连接之前没有收到通知。试试看

代码语言:javascript
复制
BluetoothDevice currentDev = (BluetoothDevice) container.getDevice();

        currentDev.setTrusted(true);
        if(!currentDev.getConnected()) {
            currentDev.connect();
        }
        logger.info(currentDev.getName());

然后获取所有服务、描述符并尝试启用以下通知:

代码语言:javascript
复制
    public void findServiceAndCharacteristic(BlueToothDeviceContainer container, String serviceUid){
    for (BluetoothGattService service : container.getGattServices()) {
            if(service.getUUID().equals(CUSTOM_SHUTTER_SERVICE_2.value) ||
                    service.getUUID().equals(CUSTOM_SHUTTER_SERVICE.value) ||
                    service.getUUID().equals(GENERAL_DEVICE_INFORMATION.value)){
                List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
                for(BluetoothGattCharacteristic ch : characteristics){
                    logger.info(ch.getUUID());
                    try {

                        List<BluetoothGattDescriptor> descrs = ch.getDescriptors();
                        for(BluetoothGattDescriptor ds : descrs){
                            ds.enableValueNotifications(new BluetoothNotification<byte[]>() {
                                @Override
                                public void run(byte[] bytes) {
                                    logger.info(ds.getUUID() + "getted");
                                    logger.info("BUTTON WAS PUSHED!!!");
                                }
                            });
                        }
                    } catch (BluetoothException ex){
                        logger.warn(ch.getUUID() + " does not work.");
                    }
                    try{
                        BluetoothNotification btnm = new BluetoothNotification<byte[]>() {
                            @Override
                            public void run(byte[] bytes) {
                                logger.info(ch.getUUID() + "getted CH");
                                logger.info("BUTTON WAS PUSHED!!!");

                            }
                        };
                        ch.enableValueNotifications(btnm);
                } catch (BluetoothException ex){
                    logger.warn(ch.getUUID() + " does not work.");
                }
                    
                    }

但是run方法不起作用。我做错什么了,有人知道吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-10 10:05:29

问题不在图书馆。HID特性的问题。在设备上没有找到它,所以没有从它发出任何通知。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73323189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档