B
B
Ben L2022-03-29 15:16:13
Android
Ben L, 2022-03-29 15:16:13

How to exchange messages via bluetooth in android application?

Hey!

I'm making an android app that needs to exchange messages with another (existing) bluetooth app (I've never done this before). Based on examples from the Internet, the code turned out:

while (socket == null) {
  try {
    serverSocket = BluetoothAdapter.getDefaultAdapter().listenUsingRfcommWithServiceRecord(
      APP_NAME, UUID.fromString(UUID_STR)
    );
    socket = serverSocket.accept();
  } catch (IOException ex) {
    ex.printStackTrace();
  }
}

which stops at line c acceptand throws an exception from time to time.
Can this be fixed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question