【问题标题】:Bluetooth Server Android - Client Java Bluecove. UUID?蓝牙服务器 Android - 客户端 Java Bluecove。 UUID?
【发布时间】:2013-06-21 14:43:02
【问题描述】:

我正在编写一个应用程序来在我的智能手机和使用蓝牙设备的计算机之间进行通信。

我正在使用Bluecove 来管理计算机上的蓝牙,以及用于我的安卓设备的安卓 API。

但是,当我调试时,什么都没有发生。我认为问题在于 UUID 错误。我不确定如何让设备相互识别,以便建立连接。

我已经阅读了一些关于这些标签的其他“问题”,但我尝试过的并没有解决我的问题:

这是我目前所写的:

  1. 对于 tho android (Server)(这是建立连接的函数)

    公共无效连接套接字(){ blueAdapter.cancelDiscovery(); // 取消发现,因为它会减慢连接速度

    final BluetoothServerSocket serverSocket;
    BluetoothServerSocket sSocket= null;
    try{
        sSocket = blueAdapter.listenUsingRfcommWithServiceRecord("BluetoothJANE", MY_UUID);
    }catch(IOException e){}
    serverSocket = sSocket;
    
    Thread acceptThread = new Thread(new Runnable() {
    
        @Override
        public void run() {
            BluetoothSocket socket = null;
            while(true){
                try{
                    socket = serverSocket.accept();
                }catch(IOException e){
                    break;
                }
                if(socket != null){
                    try{
                        iStream = socket.getInputStream();
                        oStream = socket.getOutputStream();
                    } catch(IOException e){}
                }
            }
        }
    });
    acceptThread.start();
    

    }

  2. 对于 PC 上的 java 应用程序(这是管理蓝牙连接的类的构造函数(它在一个独立的线程上))

    公共模块蓝牙(){

    StreamConnectionNotifier notifier = null;
    StreamConnection connection = null;
    
    try {
        blueDevice = LocalDevice.getLocalDevice();
        blueDevice.setDiscoverable(DiscoveryAgent.GIAC);
    
        String url = "btspp://localhost:" + MY_UUID.toString()
                + ";name=RemoteBluetooth";
        notifier = (StreamConnectionNotifier) Connector.open(url);
    
    } catch (BluetoothStateException e) {
        System.out
                .println("ModuleBluetooth: Error getting the bluetooth device");
    } catch (IOException e) {
    }
    System.out.println("waiting for connection...");
    try {
        connection = notifier.acceptAndOpen();
        System.out.println("Conenction created");
    } catch (IOException e) {
        System.out.println("Can not create the connection");
    }
    

    }

有人可以帮帮我吗?任何想法将不胜感激。

我也尝试使用一些函数来获取 UUID(在 android 中),例如 [fetchUuidsWithSdp][2](以及相关函数),但 eclipse 无法识别这些函数(似乎它们没有存在于“我的”API 中)。

http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#fetchUuidsWithSdp%28%29

【问题讨论】:

    标签: java android bluetooth bluecove


    【解决方案1】:

    试试这个例子,http://luugiathuy.com/2011/02/android-java-bluetooth/。我也遇到了与 UUID 相关的问题,在这个例子中,Converting UUID to 00001101-0000-1000-8000-00805F9B34FB 是开箱即用的。见此链接:http://www.avetana-gmbh.de/avetana-gmbh/produkte/doc/javax/bluetooth/UUID.html

    【讨论】:

    猜你喜欢
    • 2018-01-01
    • 2016-09-18
    • 1970-01-01
    • 2015-06-14
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多