我想从服务器连接到客户端的设备。在我的应用程序中,我使用的是AcceptThread类:
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
public AcceptThread() {
BluetoothServerSocket tmp = null;
try {
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) {
Log.e(TAG, "Socket's listen() method failed", e);
}
mmServerSocket = tmp;
}
public void run() {
BluetoothSocket socket = null;
while (true) {
try {
socket = mmServerSocket.accept();
} catch (IOException e) {
Log.e(TAG, "Socket's accept() method failed", e);
break;
}
if (socket != null) {
manageMyConnectedSocket(socket);
try {
mmServerSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
}
此代码适用于三星Galaxy J3。 但在三星Galaxy S6和联想Tab3 10上,应用程序停止在线 socket = mmServerSocket.accept(); 在Lenovo选项卡上,我收到以下错误:
Socket's accept() method failed
java.io.IOException: Try again
at android.net.LocalSocketImpl.readba_native(Native Method)
at android.net.LocalSocketImpl.-wrap3(LocalSocketImpl.java)
at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:101)
at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:688)
at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:649)
at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:463)
at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:158)
三星手机都有Android 7.0。
什么可以在三星S6阻止接受蓝牙插座?