2

想要连接到设备并开始从外部设备接收数据现在能够列出设备并与之配对.....现在希望连接到它并开始从它接收数据

Is there any way because i dont exactly know wat kind of data it is sending 
means in which formate etc ...

that is Bluetooth device is continuously sends data to app so the app should continuously receive data

4

2 回答 2

3

在服务中使用 listenUsingRfcommWithServiceRecord 而不是此代码

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
            btSocket = (BluetoothSocket) m.invoke(device, 1);  
于 2013-01-11T11:26:03.310 回答
0

您的问题的答案如下

有什么办法吗,因为我不完全知道它发送的数据类型是哪种甲酸盐等...

是的,有两种方法可以做到

1)使用意图

 Intent i = new Intent(Intent.ACTION_SEND);
 i.setType("image/jpeg");
 i.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/file.jpg")); startActivity(Intent.createChooser(i, "Send Image"));

使用内置蓝牙发送数据的代码示例

2)使用使用套接字连接和蓝牙管理器的开源代码通过代码来完成。以下是开源代码的链接

blueterm 开源代码

通过蓝牙发送的数据采用字节数组的形式,您必须对其进行解析并将其转换为字符串或您想在代码中使用的任何形式。

蓝牙有两个东西

1)配对。

2) 全局连接。

如果您使用第一种蓝牙方法(通过意图),设备将配对,但连接不会连续。在建立发送数据连接时,否则连接不存在。但是,如果您使用的是 blueterm 开源代码,那么您的配对和连接是恒定的,并且在用户需要之前不会中断。

因此,您需要哪种蓝牙功能取决于您。

让我知道我的回答是否解决了您的问题

于 2013-01-11T11:35:05.617 回答