我有一台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();
任何帮助或例子都会有所帮助。
您更改代码行
socket=device.createRfcommSocketToServiceRecord(generalUuid);
通过
方法m;m=设备.getClass()。getMethod("createRfcommSocket",new Class[]{int.Class});
tmp=(蓝牙插座)m.invoke(设备,1);
mmSocket=tmp;
mmSocket.connect();
在Android 中
您可以将bluecove用于android。将bluecove库和bluecove android添加到您的构建路径中,工作应该会更容易。