Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android蓝牙Java,恒定的蓝牙流填充阵列并写入SD卡_Java_Android_Arrays_Bluetooth_Buffer - Fatal编程技术网

Android蓝牙Java,恒定的蓝牙流填充阵列并写入SD卡

Android蓝牙Java,恒定的蓝牙流填充阵列并写入SD卡,java,android,arrays,bluetooth,buffer,Java,Android,Arrays,Bluetooth,Buffer,我正在编写一个Android应用程序,它使用蓝牙将数据(字节)流到另一个类的数组中。这背后的想法是记录一定数量的数据(即缓冲区[60000]),当数据满时,将缓冲区写入文件并存储在SD卡上 我遇到的问题是,每次调用bluetooth类时,它都会处理HandleBluetooth.write(缓冲区,字节)方法;为了发送到HandleBluetooth类,我的缓冲区索引在每次传递时都被重置。缓冲区的索引和缓冲区都是全局变量,这让我很困惑,为什么每次HandleBluetooth.write(缓冲区

我正在编写一个Android应用程序,它使用蓝牙将数据(字节)流到另一个类的数组中。这背后的想法是记录一定数量的数据(即缓冲区[60000]),当数据满时,将缓冲区写入文件并存储在SD卡上

我遇到的问题是,每次调用bluetooth类时,它都会处理HandleBluetooth.write(缓冲区,字节)方法;为了发送到HandleBluetooth类,我的缓冲区索引在每次传递时都被重置。缓冲区的索引和缓冲区都是全局变量,这让我很困惑,为什么每次HandleBluetooth.write(缓冲区,字节)时都将索引设置回0;被调用,因此我永远无法填充缓冲区将其写入文件

这是我的密码: BluetoothSerialService.java

        public void run() {
        Log.i(TAG, "BEGIN mConnectedThread");
        byte[] buffer = new byte[9999];
        int bytes;

        // Keep listening to the InputStream while connected
        while (true) {
            try {
                // Read from the InputStream
                bytes = mmInStream.read(buffer);

                HandleBluetooth.write(buffer, bytes);
                // Send the obtained bytes to the UI Activity
                //mHandler.obtainMessage(BlueTerm.MESSAGE_READ, bytes, -1, buffer).sendToTarget();

                String a = buffer.toString();
                a = "";
            } catch (IOException e) {
                Log.e(TAG, "disconnected", e);
                connectionLost();
                break;
            }
        }
    }
车把蓝牙等级:

        public static void write(byte[] buffer, int length) {
        byte[] readBuf = (byte[]) buffer;
        data_length = length;
        for (x = 0; x < data_length; x++) {
            raw = UByte(readBuf[x]);

            if (odd_even_flag == 0) {
                buffer1[out_index] = raw;
                // System.out.println("ch1: " + buffer1[out_index]);
                odd_even_flag = 1;

            } else {
                buffer2[out_index] = raw;
                // System.out.println("ch2: " + buffer2[out_index]);
                odd_even_flag = 0;

            }
            if (x % 10000 == 0) {
                Write2File(buffer1, buffer2);
            }
            out_index++;
            if (x >= 60000) {
                StopIncomingData();
                break;
            }
        }
    }
公共静态无效写入(字节[]缓冲区,整数长度){
字节[]readBuf=(字节[])缓冲区;
数据长度=长度;
对于(x=0;x=60000){
停止输入数据();
打破
}
}
}
如您所见,我一直在尝试使用out_index(一个全局类变量)对缓冲区进行索引

我觉得这是一件愚蠢的事情,我在看这里。请指导我正确的方向,这样我就可以理解为什么每次调用该方法时都会重置索引