发送基于 Android 的环境监测软件开发 8 相应的字符串 2 、主要程序代码 final Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ try { sp =new SerialPort(new File("/dev/ttyS2"),115200); }catch (SecurityException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } mOutputStream = (FileOutputStream) sp.getOutputStream(); mInputStream = (FileInputStream) sp.getInputStream(); Toast.makeText(getApplicationContext(), "open", Toast.LENGTH_SHORT).show(); } }); final Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ try { mOutputStream.write(new String("A0#").getBytes()); } catch (IOException e){ e.printStackTrace();