Example connecting Android and Bluecove on a Mac

白昼怎懂夜的黑 提交于 2019-12-11 09:21:14

问题


I have an Android device (HTC Incredible) and I would like to setup bluetooth communication between the android phone and a MacBook Pro. I have got bluecove to start on the Mac and I have done coding using Sockets in Android, but I can not get a connection working. Here is my andriod code

BluetoothDevice device = reciever.getDevice("00:25:00:XX:XX:XX"); //my bluetooth address
UUID generalUuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
socket = device.createRfcommSocketToServiceRecord(generalUuid);
socket.connect();
writer = new OutputStreamWriter(socket.getOutputStream());
reader = new InputStreamReader(socket.getInputStream());

on the Mac

String serverUUID = "btspp://localhost:0000110100001000800000805F9B34FB;name=matt";
StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(serverUUID);
StreamConnection connection = notifier.acceptAndOpen();
// prepare to send/receive data
byte buffer[] = new byte[100];
String msg = "hello there, client";
InputStream is = connection.openInputStream();
OutputStream os = connection.openOutputStream();

Any help or examples would be helpful.


回答1:


You change the line of code

socket = device.createRfcommSocketToServiceRecord (generalUuid);

by

Method m; m = device.getClass (). getMethod ("createRfcommSocket", new Class [] {int.class});

tmp = (BluetoothSocket) m.invoke (device, 1);

mmSocket = tmp;

mmSocket.connect ();

in Android




回答2:


you can use bluecove for android. add the bluecove library and the bluecove-android to your build path and the work should be easier.



来源:https://stackoverflow.com/questions/6449134/example-connecting-android-and-bluecove-on-a-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!