I have a Bluetooth application that accepts connections from other Bluetooth devices and receives a Stream object from them. I need help getting the data as a string so I can display in a TextView object I have in my app.I tried the method below from Microsoft documentations but the target variable that should hold the string from the Stream is of type int and so am unsure if doing textView.Text=data.ToString()
on an int object will display the data from the devices.
BluetoothSocket source_device = mysocket.Accept();
// get the input and output streams
output = source_device.OutputStream;
input = source_device.InputStream;
// check if data is available and write it to our UI object
if (input.IsDataAvailable())
{
// way of reading the data from stream on Microsoft documentation
byte[] bytes= new byte[input.Length];
int bytesToRead = (int)input.Length;
int numBytesRead = 0;
do
{
// Read may return anything from 0 to 10.
int n = input.Read(bytes, numBytesRead, 10);
numBytesRead += n;
bytesToRead -= n;
} while (bytesToRead>0);
// am unsure if this will display the data I need as it is just an int
_data.Text = numBytesRead.ToString();