Bonjour Je veux faire la conversation entre les appareils Android. J'utilise BluetoothChat pour cela, mais cela ne fonctionne pas Je ne peux pas lire correctement les données d'un autre appareil.BluetoothChat ne fonctionne pas
Conversation est:
Me: troène
Appareil: p Appareil: rivet
Pouvez-vous me aider?
ConnectedThread private class extends Thread {
private final InputStream mmInStream;
private final OutputStream mmOutStream;
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread");
mmSocket = socket;
//InputStream tmpIn = null;
OutputStream tmpOut = null;
BufferedInputStream tmpIn=null;
int INPUT_BUFFER_SIZE=32;
// Get the BluetoothSocket input and output streams
try {
//tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
tmpIn = new BufferedInputStream(socket.getInputStream(),INPUT_BUFFER_SIZE);
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
Quels sont les deux appareils? Le bluetooth de certains appareils ne fonctionne pas, même s'ils sont sur Android 2.0. Par exemple le HTC Droid. –
C'est la même question que http://stackoverflow.com/questions/9270965/bluetooth-spp-receive-some-the-package-frame-can-lost-or/32887129#32887129 – jgrocha