蓝牙传输字符串不正确

时间:2016-07-19 15:06:25

标签: java android bluetooth

所以我制作了一个必须通过蓝牙连接发送Node **pathList; Node *firstPath = (Node *)malloc(sizeof(Node)); pathList = &firstPath; ...//add new Node to firstPath.. Node *secondPath = (Node *)malloc(sizeof(Node)); *(pathList+1) = secondPath;// IS THIS LEAGLE? 的应用。 Arraylist<String>可能长达数百行。我现在只用几行数据测试它。当我将数据传输到另一部手机时,它立即将其打印到logcat。它传输线路起点的一部分,但随后发送了一大堆这些问号。当我玩ArrayList<String>大小时,降低它似乎摆脱了很多问号,但线条没有被保留,提高它似乎发送更多的问号。无论如何 - 看一下控制台输出: Console output

发送代码:

byte[] buffer

这是接收代码:

public void run() {
        btAdapter.cancelDiscovery(); // discovery is heavy on the Bluetooth bandwith

        try { 
            socket.connect();

            // Decompile the enter file system of this event into one giant arraylist<string>
            EventDecompiler decompiler = new EventDecompiler(getApplicationContext());
            ArrayList<String> lines = decompiler.decompile(eventName, false);  

            ConnectedThread thread = new ConnectedThread(socket);
            thread.start();

            // First, let the other device know how much information we're sending
            thread.write(String.valueOf(lines.size()).getBytes());

            for(int i = 0; i < lines.size(); i++) {
                thread.write(lines.get(i).getBytes());
            }
        } catch(IOException e) {
            cancel();
            return;
        }
    }
    public void write(byte[] bytes) {
        try {
            outStream.write(bytes);
        } catch(IOException e) {}
    }

有关如何动态缩放缓冲区大小或出现其他错误的任何想法吗?

0 个答案:

没有答案