2013-06-24 89 views
0

我正在做一個Android應用程序,它可以從藍牙接收數據並將其顯示爲波形。現在的問題是我想顯示數據在一個文本視圖來確認數據是否正確,但我顯示無法識別(如@ & zA ...)。任何人都可以幫助將數據轉換爲8位值?謝謝 !藍牙接收數據並將其顯示在文本視圖

相關的編碼如下所示:

Handler handler = new Handler() { 
      @Override 
      public void handleMessage(Message msg) { 
       if (msg.what==READ) { 
        String str = (String)msg.obj; 
        textView1.setText(str); 
       } 
       super.handleMessage(msg); 
       } 
     }; 

    private class ConnectedThread extends Thread { 
     private final InputStream mmInStream; 
     public ConnectedThread(BluetoothSocket socket) { 
      InputStream tmpIn = null; 
      try { 
       tmpIn = socket.getInputStream(); 
      }catch (IOException e) { } 
      mmInStream = tmpIn; 
     } 

     public void run() { 
      byte[] buffer = new byte[5]; 
      int bytes; // bytes returned from read() 

      // Keep listening to the InputStream until an exception occurs 
      while (true) { 
       try { 
        // Read from the InputStream 
        bytes = mmInStream.read(buffer); 
        // Send the obtained bytes to the UI activity 
        String str = new String(buffer); 
        temp = byteToInt(buffer); //Convert byte to int 
        handler.obtainMessage(READ, bytes, -1, str).sendToTarget(); 

       }catch (Exception e) { 
        System.out.print("read error"); 
        break; 
       } 

      } 
     } 
    } 
+0

直視他們的Android樣品藍牙聊天應用程序/樣品/機器人-17/BluetoothChat –

回答

相關問題