1

我有一个 Android 设备(HTC Incredible),我想在 android 手机和 MacBook Pro 之间设置蓝牙通信。我已经在 Mac 上启动了 bluecove,并且我已经在 Android 中使用 Sockets 完成了编码,但我无法使连接正常工作。这是我的安卓代码

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();

任何帮助或示例都会有所帮助。

4

2 回答 2

0

您可以将 bluecove 用于 android。将 bluecove 库和 bluecove-android 添加到您的构建路径中,工作应该会更容易。

于 2011-11-02T11:11:30.457 回答
0

您更改代码行

socket = device.createRfcommSocketToServiceRecord (generalUuid);

经过

方法m;m = 设备.getClass()。getMethod("createRfcommSocket", new Class [] {int.class});

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

mmSocket = tmp;

mmSocket.connect();

在安卓中

于 2011-07-18T14:02:27.493 回答