A.S.
A.S.

Reputation: 3

Android bluetooth chat example - how to make user wait for message

I am explaining bluetooth chat example and trying to find a way to make one device only able to write after it gets a message from other device. e.g. 1st device connects to 2nd device, so 2nd device cant write (send message) until it gets message from 1st device. Tried to do some searching but found nothing... Maybe anyone could help me with this? Example changes in code would be appreciated. Thanks in advance.

Upvotes: 0

Views: 713

Answers (1)

Angelo.Hannes
Angelo.Hannes

Reputation: 1729

I am not aware of any mechanism provided by bluetooth, that will help you to accomplish, what you are trying to implement. But you can do something like that

class YourClass {
    private boolean allowedToSend = false;
    private void send() {
        if(allowedToSend) {
            allowdToSend = false;
            //Sending your data
        }
    }
    private void receive() {
        allowdToSend = true;
        //receiving your data
    }
}

Upvotes: 1

Related Questions