我有一个Android设备(HTC Incredible),我想在Android手机和MacBook Pro之间设置蓝牙通信。我已经在Mac上启动了bluecove并且我已经使用Android中的套接字进行了编码,但我无法使用连接。这是我的andriod代码
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());
在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();
任何帮助或示例都会有所帮助。
答案 0 :(得分:0)
您更改了代码行
socket = device.createRfcommSocketToServiceRecord(generalUuid);
通过
Android中的方法m; m = device.getClass()。 getMethod(“createRfcommSocket”,new Class [] {int.class});
tmp =(BluetoothSocket)m.invoke(device,1);
mmSocket = tmp;
mmSocket.connect();
答案 1 :(得分:0)
你可以使用bluecove for android。 将bluecove库和bluecove-android添加到您的构建路径中,工作应该更容易。