在pc端的adb 输入 adb shell am broadcast -a ADB_INPUT_TEXT --es msg "你好嗎! Hello!" 没出现乱码
但是在代码上
String adb="am broadcast -a ADB_INPUT_TEXT --es msg '" + value + "'";
execRootCmd(adb);
public static String execRootCmd(String cmd) { String result = ""; DataOutputStream dos = null; DataInputStream dis = null;
try { Process p = Runtime.getRuntime().exec("su");// 经过Root处理的android系统即有su命令 dos = new DataOutputStream(p.getOutputStream()); dis = new DataInputStream(p.getInputStream()); // settings put global airplane_mode_on 0 // am broadcast -a android.intent.action.AIRPLANE_MODE dos.writeBytes(cmd + "\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); String line = null; while ((line = dis.readLine()) != null) { Log.d("result", line); result += line; } p.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally {