• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Continuous bluetooth stream

Hi!
I'm having trouble sending a continuous stream of data via bluetooth.
First, is it possible?, and then, how can i do it? (with a long press button)
Do I have to create a socket and send the data in a 'while' loop, because i tried but I'm not sure i did it the right way.
 
Difficult to advise if you did it 'the right way' until we see the way that you did it.
 
I tried 2 things: first, i added a while loop in the send method, and then i added a loop in the onLongClick one.

1)
public void sendData(String data) {
while (true) {
try {
OutputStream sendStream = socket.getOutputStream();
sendStream.write(data.getBytes());
sendStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}

2)
b4.setOnLongClickListener(new View.OnLongClickListener(){
while(true){
public boolean onLongClick(View v){
sendData("402");
Toast.makeText(getApplicationContext(), "Data stream : '402'", Toast.LENGTH_SHORT).show();
return true;
}
}
});

But am I on the right path? I mean, should i create a socket and send the data in a 'while' loop, in order to repeat the action of sending the data?
 
Back
Top Bottom