發現的this Link謝謝問題:
Runtime r = Runtime.getRuntime();
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("echo -e \"AT\\r\" > /dev/smd0\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
\n
需要在命令的結束和一些命令有什麼需要su
我們需要使用DataOutPutStream
發送命令。
編輯:
下面代碼我可以讀取它:
public class read implements Runnable {
private Thread mBlinker;
private ArrayList<String> output = new ArrayList<String>();
public String getResponce() {
if (output.size() != 0) {
String ans = output.get(0);
output.remove(0);
return ans;
}
return null;
}
public void start() {
mBlinker = new Thread(this);
mBlinker.start();
}
public void stop() {
mBlinker = null;
}
private DataInputStream dis;
private DataOutputStream dos;
@Override
public void run() {
System.out.println("START READ");
try {
Runtime r = Runtime.getRuntime();
Process process = r.exec("su");
dos = new DataOutputStream(process.getOutputStream());
dos.writeBytes("cat /dev/smd0\n");
dos.flush();
dis = new DataInputStream(process.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
while (mBlinker != null) {
try {
int av = dis.available();
if (av != 0) {
byte[] b = new byte[av];
dis.read(b);
output.add(new String(b));
System.out.println(new String(b) + "Recieved form modem");
}
else
{
Thread.sleep(100);
}
} catch (IOException e) {
if (e.getMessage() != null)
System.out.println(e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
dos.writeBytes("exit\n");
dos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("STOP READ");
}
}
在上面提供的同一鏈接上, line:String currUid = osRes.readLine(); – Muzikant 2012-02-18 23:29:02