jonbonazza
Android Expert
Ok, well, thanks to the help of a fellow developer from another forum who is having a similar issue,
I was able to get a little further with this. Basically, I have a J2SE app running on a PC that is broadcasting a string of text over bluetooth (This functionality is working fine. The string is being sent flawlessly), and an app on my android phone that reads this incomeing stream of text via an InputStream object and then sets the text property of a TextView object to contain this string of text.
My problem is in the android app. It connects via bluetooth fine, but when it goes to read the string, it reads 0 bytes and thus, the text that is placed in the text property of the TextView object is just a bunch of garbled garbage.
Any ideas?
Here is the relevant code:
I was able to get a little further with this. Basically, I have a J2SE app running on a PC that is broadcasting a string of text over bluetooth (This functionality is working fine. The string is being sent flawlessly), and an app on my android phone that reads this incomeing stream of text via an InputStream object and then sets the text property of a TextView object to contain this string of text.
My problem is in the android app. It connects via bluetooth fine, but when it goes to read the string, it reads 0 bytes and thus, the text that is placed in the text property of the TextView object is just a bunch of garbled garbage.
Any ideas?
Here is the relevant code:
Code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.TextView);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.enable();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
try
{
btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
btSocket.connect();
inStream = btSocket.getInputStream();
}
catch (IOException e1)
{
e1.printStackTrace();
}
BufferedInputStream bis = new BufferedInputStream(inStream);
byte[] msgBuffer = new byte[1024];
int numBytes = 0;
try
{
numBytes = bis.read(msgBuffer);
}
catch (IOException e)
{
}
try
{
btSocket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
String msg = msgBuffer.toString();
//String msg = Integer.toString(numBytes);
textView.setText(msg);
}