我正在努力了解工作客户端 - 服务器蓝牙.android是客户端的地方.PC是服务器.
我找到了代码.这工作了三星galaxy 10.1(android 3.2),但不适用于三星galaxy s(android 2.3.3)和htc wildfire s(android 2.2).
MY_UUID = UUID.fromString("04c6093b-0000-1000-8000-00805f9b34fb");
Run Code Online (Sandbox Code Playgroud)
04-25 18:32:37.023: D/BluetoothCommandService(13665): setState() 1 -> 2
04-25 18:32:37.033: I/BluetoothCommandService(13665): BEGIN mConnectThread
04-25 18:32:37.063: E/BluetoothService.cpp(102): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
04-25 18:32:37.103: E/BluetoothCommandService(13665): Unable to start Service Discovery
04-25 18:32:37.103: E/BluetoothCommandService(13665): java.io.IOException: Unable to start Service Discovery
04-25 18:32:37.103: E/BluetoothCommandService(13665): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:367)
04-25 18:32:37.103: E/BluetoothCommandService(13665): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)
04-25 18:32:37.103: E/BluetoothCommandService(13665): at com.luugiathuy.apps.remotebluetooth.BluetoothCommandService$ConnectThread.run(BluetoothCommandService.java:258)
04-25 18:32:37.103: D/BluetoothCommandService(13665): setState() 2 -> 1
Run Code Online (Sandbox Code Playgroud)
您的设备无法进行服务发现(我认为如此).
我已经阅读了许多三星设备和HTC设备的BT问题,但那些专门用于L2CAP/HID配置文件的设备.Soln:如果您使用的是L2CAP,可以使用SPP或RFCOMM
如果您使用上述解决方案之一,请尝试使用标准UUID
SPP 00001101-0000-1000-8000-00805F9B34FB
RFCOMM 00000003-0000-1000-8000-00805F9B34FB
编辑
或者,您可以尝试使用反射来获得类似于以下方法的套接字连接
private static BluetoothSocket createBluetoothSocket(
int type, int fd, boolean auth, boolean encrypt, String address, int port){
try {
Constructor<BluetoothSocket> constructor = BluetoothSocket.class.getDeclaredConstructor(
int.class, int.class,boolean.class,boolean.class,String.class, int.class);
constructor.setAccessible(true);
BluetoothSocket clientSocket = (BluetoothSocket)
constructor.newInstance(type,fd,auth,encrypt,address,port);
return clientSocket;
}catch (Exception e) { return null; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7283 次 |
| 最近记录: |