安卓和PC蓝牙应用之间的连接

4
我正在开发一个蓝牙应用程序,涉及将我的Android蓝牙应用程序与在计算机上运行的服务器连接起来。该服务器也是使用Blue-cove API制作的蓝牙应用程序。
现在我遇到的问题是我无法让我的移动应用程序与计算机服务器应用程序建立连接。
以下是我的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()方法的理解存在歧义。请在这方面帮助我。

1个回答

5
我刚刚完成了一个类似的应用程序,但连接时遇到了问题。看起来你的代码片段与我正在遵循的示例相似,因此如果能看到更多的代码,这将有助于解决问题。建议首先检查您尝试连接的 PC 上是否存在 MY_UUID。
我在博客中发布了我的示例,包括客户端和服务器端,请访问http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html
希望这可以帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接