首先我必须说,我是android的初学者。我正在开发一个应用程序,它应该通过蓝牙连接到没有任何操作元件(没有按钮,没有显示)的测量仪器,并接收测量数据。不幸的是,我对测量仪器和制造商也不太了解。我所知道的一切是,我必须通过RFCOMM进行通信,当我与android配对时,我必须将序列号作为PIN(09000)发送。到目前为止,这是可行的。android与设备配对。当尝试连接时,它首先建立连接,几秒钟后中断。我用的是三星Galaxy S3和HTC Sensation。
在这里你可以找到我完整的蓝牙连接类:
http://iukp.chefti.com/JAVA/AndroidBluetooth.java以下是logcat输出以供更多参考:
12-22 17:24:56.104: I/System.out(6079): ConnectThread()
12-22 17:24:56.104: V/BluetoothSocket.cpp(6079): initSocketNative
12-22 17:24:56.104: V/BluetoothSocket.cpp(6079): ...fd 51 created (RFCOMM, lm = 26)
12-22 17:24:56.104: V/BluetoothSocket.cpp(6079): initSocketFromFdNative
12-22 17:24:56.109: I/System.out(6079): ConnectThread() try succesfull
12-22 17:24:56.114: I/System.out(6079): ConnectThread.run()
12-22 17:24:56.114: I/System.out(6079): mmSocket.connect 0.1()
12-22 17:24:56.124: D/BluetoothUtils(6079): isSocketAllowedBySecurityPolicy start : device null
12-22 17:24:57.109: V/BluetoothSocket.cpp(6079): connectNative
12-22 17:24:57.174: V/BluetoothSocket.cpp(6079): ...connect(51, RFCOMM) = 0 (errno 115)
12-22 17:24:57.179: I/System.out(6079): true
12-22 17:24:57.184: I/System.out(6079): ConnectedThread()
12-22 17:24:57.184: I/System.out(6079): socket.X tried
12-22 17:24:57.184: I/System.out(6079): manageConnectedSocket()
12-22 17:24:57.184: I/System.out(6079): run()
12-22 17:24:57.184: I/System.out(6079): ConnectThread() try succesfull - run()
12-22 17:24:57.184: I/System.out(6079): SON F BICHT
12-22 17:24:57.184: I/Choreographer(6079): Skipped 67 frames! The application may be doing too much work on its main thread.
12-22 17:24:58.189: D/dalvikvm(6079): GC_CONCURRENT freed 91K, 6% free 12469K/13191K, paused 21ms+4ms, total 76ms
12-22 17:24:58.209: V/BluetoothSocket.cpp(6079): abortNative
12-22 17:24:58.209: V/BluetoothSocket.cpp(6079): ...asocket_abort(51) complete
12-22 17:24:58.209: V/BluetoothSocket.cpp(6079): destroyNative
12-22 17:24:58.209: V/BluetoothSocket.cpp(6079): ...asocket_destroy(51) complete
如有任何提示或建议,我将不胜感激。对不起,我的英语不好。
既然你六个月前问过这个问题,我希望你已经解决了你的问题,但对于其他人来说,你的问题可能与此有关:
Android蓝牙SPP与Galaxy S3
看看这个问题的答案。