简体   繁体   中英

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. 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. However, my attempt to read from the socket and display to the strings to the TextView has been futile. Here is the Android client and here is the logcat to evidence that the server works fine. Some Android & java guru to kindly assist. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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