Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以配对连接,可以发送数据,但是无法接收到数据,也没有报错信息。 #5

Open
sunguiyong opened this issue Feb 1, 2021 · 1 comment

Comments

@sunguiyong
Copy link

可以配对连接,可以发送数据,但是无法接收到数据,也没有报错信息。

CbtManager.getInstance().startServiceListener(new ServiceListenerCallback() {
@OverRide
public void onStartError(Throwable throwable) {
CbtLogs.e(throwable.getMessage());
}

            @Override
            public void onDataListener(String s, BluetoothDevice device) {
                CbtLogs.e("onDataListener:" + s);
            }
        });
@rainfoam
Copy link

这个库确实没有客户端收数据的方法,需要自己手动写。
蓝牙连接成功后开启子线程接收数据:
CbtExecutor.getInstance().execute(new Runnable() {
@OverRide
public void run() {
ByteArrayOutputStream byteArrayOutputStream;
byte[] buffer = new byte[1024];
int bytes;
try {
InputStream inputStream = mBluetoothSocket.getInputStream();
while (true) {
while ((bytes = inputStream.read(buffer)) != -1) {
byteArrayOutputStream = new ByteArrayOutputStream();
byteArrayOutputStream.write(buffer, 0, bytes);
//resole是并包的方法,不并包数据是错乱的
byte[] resole = ReadUtil.resole(byteArrayOutputStream.toByteArray());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants