0
I am developing an android app for bluetooth connection, currently my application is listing the paired devices and search new devices.
I need at this point an example code that picks up the address 1b:2f:5d:6a:7a
and submit a matching request.
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
public AcceptThread() {
// Use a temporary object that is later assigned to mmServerSocket,
// because mmServerSocket is final
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app's UUID string, also used by the client code
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) { }
mmServerSocket = tmp;
}
public void run() {
BluetoothSocket socket = null;
// Keep listening until exception occurs or a socket is returned
while (true) {
try {
socket = mmServerSocket.accept();
} catch (IOException e) {
break;
}
// If a connection was accepted
if (socket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(socket);
mmServerSocket.close();
break;
}
}
}
/** Will cancel the listening socket, and cause the thread to finish */
public void cancel() {
try {
mmServerSocket.close();
} catch (IOException e) { }
}
}
Hello @Gilliard-saints have you tried anything? if yes it would be interesting to put your attempt so that we can analyze and correct/improve your code.
– Erlon Charles
I added my question the code I have, but I do not know if it is to request pairing and do not know where I enter the address of the device I want to connect.
– Desenvolvedor