1. Download our Official Android App: Forums for Android!

Apps Continuous bluetooth stream

Discussion in 'Android Development' started by Hugo Trombert, Aug 2, 2016.

  1. Hugo Trombert

    Hugo Trombert Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jul 24, 2016

    Jul 24, 2016
    4
    0
    5
    Male
    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.
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,887
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,887
    11,548
    1,988
    Male
    Software developer
    South West of England
    Difficult to advise if you did it 'the right way' until we see the way that you did it.
     
    Thom likes this.
  3. Hugo Trombert

    Hugo Trombert Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jul 24, 2016

    Jul 24, 2016
    4
    0
    5
    Male
    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?
     

Share This Page

Loading...