我正在开发一个蓝牙应用程序,涉及将我的Android蓝牙应用程序与在计算机上运行的服务器连接起来。该服务器也是使用Blue-cove API制作的蓝牙应用程序。
现在我遇到的问题是我无法让我的移动应用程序与计算机服务器应用程序建立连接。
以下是我的Android应用程序代码:
现在我遇到的问题是我无法让我的移动应用程序与计算机服务器应用程序建立连接。
以下是我的Android应用程序代码:
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mySocket = myDevice.createRfcommSocketToServiceRecord(MY_UUID);
mySocket.connect();
toast = Toast.makeText(context, "Connection established", thisClass.duration);
toast.show();
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mySocket.close();
toast = Toast.makeText(context, "Connection not established", thisClass.duration);
toast.show();
} catch (IOException closeException) { }
return;
}
这个问题出在哪里,或者我可能漏掉了什么。同时,我对socket.connect()方法的理解存在歧义。请在这方面帮助我。