使用Data INPUT STREAM通过蓝牙发送数据

时间:2017-07-10 12:27:26

标签: android bluetooth

我想了解如何使用对象数据输入流来使其适应我的代码:

public void run() {
            byte[] buffer = new byte[1048576]; // 20 bits
            int bytes;
            String strRx = "";

            while (running) {
                try {
                    bytes = connectedInputStream.read(buffer);
                    final String strReceived_freq = new String(buffer,0, bytes);
                    final String strReceived_pxx = new String(buffer,(bytes/2)+1, bytes);
                    //final int samples_sdr=new Integer(buffer,0,bytes);
                    final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";

                    runOnUiThread(new Runnable(){

                        @Override
                        public void run() {
                                Pxx_value.setText(strReceived_pxx+"\n");    // get data PXX
                                freq_value.setText(strReceived_freq+"\n"); // get data freq

                            // plot value
                          /*  for (int i=0; i<nb_points; i++)
                            {
                                freq[i]=Double.parseDouble(strReceived_freq);
                                pxx[i]=Double.parseDouble(strReceived_pxx);
                                series.appendData(new DataPoint(freq[i],pxx[i]), true,500);
                            }*/

                        }});

其实我这样做了:

DataInputStream bytes2= new DataInputStream(connectedInputStream)
byte_value=bytes2.read()

我想使用方法

readFully(byte[] b, int off, int len)

但它是无效的方法,所以我无法从这种方法中获取数据。

感谢您的帮助!

0 个答案:

没有答案