Muh*_*ooq 4 java android bluetooth
我正在开发一个蓝牙应用程序,它涉及我的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;
}
Run Code Online (Sandbox Code Playgroud)
问题出在哪里或者我可能缺少什么.而且我对socket.connect()方法的理解也很模糊.请在这方面帮助我.
我刚刚完成了类似的应用程序,并且连接有问题.看一下你的代码会有所帮助,但上面的摘录看起来就像我所遵循的例子.我首先检查您尝试连接的PC上是否存在MY_UUID.
我已经在我的博客http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html上发布了我的示例,包括客户端和服务器.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
11407 次 |
| 最近记录: |