Partage
  • Partager sur Facebook
  • Partager sur Twitter

Configurer le InStream en bluetooth

    7 juin 2018 à 10:33:40

    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 : 

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

    Voici mon run():

            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 ^^



    • Partager sur Facebook
    • Partager sur Twitter

    Configurer le InStream en bluetooth

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown