无法通过平台通道颤振从蓝牙在颤振 UI 中显示数据

时间:2021-04-09 16:13:09

标签: android flutter bluetooth

想通过平台通道在flutter UI中展示数据。 存储从蓝牙发送的数据到字符串变量 public String readMessage; 当我通过蓝牙发送数据时,我可以接收并获取 Toast 消息中的值。 这是在处理程序中完成的。 现在我如何将数据发送到颤振。?并在 UI 中显示

我的经纪人

handler = new Handler(Looper.getMainLooper()){
            @Override
            public void handleMessage(Message msg){
                if(msg.what == MESSAGE_READ){
                     readMessage = null;
                    try {
                        readMessage = new String((byte[]) msg.obj, "UTF-8");
                                               

                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                   Toast.makeText(getApplicationContext(),"MEssage"+readMessage,Toast.LENGTH_LONG).show();

                }

                if(msg.what == CONNECTION_STATUS){
                    if(msg.arg1 == 1)
                    {
                        bluetoothStatus=true;
                        result.success(bluetoothStatus);
                    }

                    else
                    {
                        bluetoothStatus=false;
                        result.success(bluetoothStatus);

                    }

                }
            }
        };

0 个答案:

没有答案