简体   繁体   English

如何从Java中的蓝牙套接字读取字符串

[英]How to read strings from a bluetooth socket in java

I am trying to read strings from a Bluetooth SPP server into my Android client. 我试图将字符串从Bluetooth SPP服务器读取到我的Android客户端中。 The server works fine, and sends the strings to the client as is evidenced in the Logcat.The LogCat indicates that bytes are read in from the btSocket. 服务器工作正常,并将字符串发送到客户端,如Logcat所示.LogCat指示从btSocket读取字节。 However, my attempt to read from the socket and display to the strings to the TextView has been futile. 但是,我尝试从套接字读取并显示到TextView的字符串是徒劳的。 Here is the Android client and here is the logcat to evidence that the server works fine. 是Android客户端,这是证明服务器运行正常的日志记录 Some Android & java guru to kindly assist. 一些Android和Java专家可以提供帮助。 Thanks. 谢谢。

Try something like this : 尝试这样的事情:

byte[] buffer = new byte[1024];
int bytes;
inFromServer = nmeaServerSocket.getInputStream();

bytes = inFromServer.read(buffer);
String readMessage = new String(buffer, 0, bytes);
Log.d(TAG, "Message :: "+readMessage);

Hope it helps you. 希望对您有帮助。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM