android - 远程蓝牙

标签 android bluetooth

我正在尝试了解客户端-服务器蓝牙的工作原理。 android是客户端。 PC 是服务器。

我找到了 code .这适用于三星 galaxy 10.1(android 3.2),但不适用于 samsung galaxy s(android 2.3.3)ans htc wildfire s(android 2.2)。

MY_UUID = UUID.fromString("04c6093b-0000-1000-8000-00805f9b34fb");

    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

最佳答案

您的设备无法发现服务(我认为是)。

  1. 我读到过有关许多三星设备和 HTC 设备的 BT 问题,但这些设备专门针对 L2CAP/HID 配置文件。 Soln:如果你使用 L2CAP,你可以使用 SPP 或 RFCOMM

  2. 如果您使用的是解决方案中提到的上述方法之一,请尝试使用标准 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; }
}

关于android - 远程蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10315376/

相关文章:

java - Android Realm : Store a non-RealmObject inside a RealmObject one

android - 在 Jenkins 的任务 gradle 中找不到 assembleRelease

java - 安卓蓝牙

python - python中的socket.recv(255)卡在等待数据上

ios - 近似于iOS中的airplay,蓝牙和相关技术的音频延迟

ios - 在后台模式下连接的外围设备(核心蓝牙)

android - 如何将一个 View 约束在两个可见性可以切换的 View 之下?

java - 机器人 : isDirectory() function always returns false

android - "No enclosing instance of type"在Android中从另一个类调用方法时出错

android - Bluetooth LE 扫描有时找不到设备