Jump to content
Sign in to follow this  
Anthony49

Android Studio - transmission de données Bluetooth HC05

Recommended Posts

 

1

Bonjour à tous,

Je tente une dernière fois ma chance, je souhaite configurer le InStream, c'est à dire ce que je peux recevoir, mais je ne sais pas où chercher etc...

J'arrive à envoyer sans problème : 

1
2
3
4
5
6
public void write(String input) {
    byte[] bytes = input.getBytes();           //converts entered String into bytes
    try {
        mmOutStream.write(bytes);
    } catch (IOException e) { }
}

Voici mon run():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public void run() {
    byte[] buffer = new byte[1024];  // buffer store for the stream
    int bytes; // bytes returned from read()
    // Keep listening to the InputStream until an exception occurs
    while (true) {
        try {
            // Read from the InputStream
            bytes = mmInStream.available();
            if(bytes != 0) {
                SystemClock.sleep(100); //pause and wait for rest of data. Adjust this depending on your sending speed.
                bytes = mmInStream.available(); // how many bytes are ready to be read?
                bytes = mmInStream.read(buffer, 0, bytes); // record how many bytes we actually read
                mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
                        .sendToTarget(); // Send the obtained bytes to the UI activity
            }
        } catch (IOException e) {
            e.printStackTrace();
 
            break;
        }
    }
}

Mon projet est à finir pour demain donc je tente une ultime fois ^^

 

 

Merci d'avance ! :)

Edited by Anthony49

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  





×
×
  • Create New...