Android 通过摩托罗拉蓝牙条形码扫描器(CS3070)读取的数据是两个字符串?

Android 通过摩托罗拉蓝牙条形码扫描器(CS3070)读取的数据是两个字符串?,android,Android,我正在通过摩托罗拉蓝牙条形码扫描仪(CS3070)读取数据。实际上,我的原始条形码数据是:1PCS3070-SR10007WW,但我得到的是双字符串示例 1P作为第一个字符串,CS3070-SR10007WW作为第二个字符串。通过蓝牙读取,所有扫描的条形码都会出现两个字符串。我希望你现在能理解我的问题。与开发人员使用的代码相同 以下是我通过蓝牙连接和读取线程中数据的代码: private class ConnectThread extends Thread { private B

我正在通过摩托罗拉蓝牙条形码扫描仪(CS3070)读取数据。实际上,我的原始条形码数据是:1PCS3070-SR10007WW,但我得到的是双字符串示例 1P作为第一个字符串,CS3070-SR10007WW作为第二个字符串。通过蓝牙读取,所有扫描的条形码都会出现两个字符串。我希望你现在能理解我的问题。与开发人员使用的代码相同

以下是我通过蓝牙连接和读取线程中数据的代码:

private class ConnectThread extends Thread {
        private BluetoothSocket mmSocket;
        private final BluetoothDevice mmDevice;

        public ConnectThread(BluetoothDevice device) {
            mmDevice = device;
            BluetoothSocket tmp = null;

            // Get a BluetoothSocket for a connection with the
            Method m;
            try {
                m = device.getClass().getMethod("createRfcommSocket",
                        new Class[] { int.class });
                try {
                    tmp = (BluetoothSocket) m.invoke(device, 1);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            } catch (NoSuchMethodException e1) {
                e1.printStackTrace();
            }

            mmSocket = tmp;
        }

        public void run() {
            setName("ConnectThread");

            // Always cancel discovery because it will slow down a connection
            mAdapter.cancelDiscovery();

            // Make a connection to the BluetoothSocket
            try {
                // This is a blocking call and will only return on a
                // successful connection or an exception
                mmSocket.connect();
            } catch (IOException e) {
                connectionFailed();
                // Close the socket
                try {
                    mmSocket.close();
                } catch (IOException e2) {
                    Log.e(TAG,
                            "unable to close() socket during connection failure",
                            e2);
                }
                // Start the service over to restart listening mode
                BluetoothService.this.start();
                return;
            }

            // Reset the ConnectThread because we're done
            synchronized (BluetoothService.this) {
                mConnectThread = null;
            }

            // Start the connected thread
            connected(mmSocket, mmDevice);
        }

        public void cancel() {
            try {
                mmSocket.close();
            } catch (IOException e) {
                Log.e(TAG, "close() of connect socket failed", e);
            }
        }
    }


private class ConnectedThread extends Thread {
        private final BluetoothSocket mmSocket;
        private final InputStream mmInStream;
        private final OutputStream mmOutStream;

        public ConnectedThread(BluetoothSocket socket) {

            mmSocket = socket;
            InputStream tmpIn = null;
            OutputStream tmpOut = null;

            // Get the BluetoothSocket input and output streams
            try {
                tmpIn = mmSocket.getInputStream();
                tmpOut = mmSocket.getOutputStream();
            } catch (IOException e) {
                Log.e(TAG, "temp sockets not created", e);
            }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }

        public void run() {

            byte[] buffer = new byte[1024];
            int bytes = 0;

            // Keep listening to the InputStream while connected
            while (true) {
                try {

                    // Read from the InputStream
                    bytes = mmInStream.read(buffer);

                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage(ScanningActivity.MESSAGE_READ,
                            bytes, -1, buffer).sendToTarget();
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    break;
                }
            }
        }

        /**
         * Write to the connected OutStream.
         * 
         * @param buffer
         *            The bytes to write
         */
        public void write(String buffer) {
            try {
                mmOutStream.write((buffer + "\n").getBytes());

                // Share the sent message back to the UI Activity
                mHandler.obtainMessage(ScanningActivity.MESSAGE_WRITE, -1, -1,
                        buffer).sendToTarget();
            } catch (IOException e) {
                Log.e(TAG, "Exception during write", e);
            }
        }

        public void cancel() {
            try {
                mmSocket.close();
                mmInStream.close();
                mmOutStream.close();
            } catch (IOException e) {
                Log.e(TAG, "close() of connect socket failed", e);
            }
        }
    }

如果有人对此有答案,请告诉我。提前谢谢

我也遇到了同样的问题。你有没有可能找到解决办法?对我来说,这只发生在“代码39”和“交错2/5”代码上。其他代码似乎也起了作用。