java - android和PC蓝牙应用程序之间的连接

标签 java android bluetooth

我正在开发一个蓝牙应用程序,它涉及将我的 android 蓝牙应用程序与计算机上运行的服务器连接。该服务器也是使用 blue-cove api 制作的蓝牙应用程序。

我现在面临的问题是我无法在我的移动应用程序和该计算机服务器应用程序之间建立连接。

这是我的安卓应用代码:

 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() 方法的理解也有歧义。请在这方面帮助我。

最佳答案

我刚刚完成了一个类似的应用程序,但在连接时遇到了问题。查看更多您的代码会有所帮助,但上面的摘录看起来像我正在关注的示例。首先,我会检查您尝试连接的 PC 上是否存在 MY_UUID。

我已经在我的博客 http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html 上发布了我的示例,包括客户端和服务器。 .

希望这对您有所帮助。

关于java - android和PC蓝牙应用程序之间的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10436785/

相关文章:

java - System.currentTimeMillis() 行为错误

android - 下拉菜单中的项目

android - 如何支持安卓产品的所有不同分辨率

android - 通过蓝牙应用程序的视频流

java - 从按钮网格中绘制特定按钮

java - 无法在 Python 3.5 中从 PyQt5 导入 QWebPage

android - SharedPreferences.getInt ("cumulative", 0) catch 22 - 如何解决?

Android 2.2 蓝牙问题(采用 BluetoothChat 示例)

ios - 核心蓝牙特性不更新值

java - 测试中未加载 Spring Boot *.hbm.xml 映射文件