不是,BluetoothServerSocket 可以使用其他可用的端口。
以下是一个使用 BluetoothServerSocket 的代码示例:
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothServerSocket serverSocket = null;
try {
// 创建一个监听端口为8的服务器套接字
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord("MyApp", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
// 处理异常
}
if (serverSocket != null) {
// 等待连接
BluetoothSocket socket = null;
try {
socket = serverSocket.accept();
} catch (IOException e) {
// 处理异常
}
if (socket != null) {
// 处理已连接的 BluetoothSocket
}
// 关闭服务器套接字
try {
serverSocket.close();
} catch (IOException e) {
// 处理异常
}
}