導航:首頁 > 程序命令 > 安卓mkshell命令

安卓mkshell命令

發布時間:2025-05-24 03:13:13

1. android apk 怎麼執行adb shell命令

Android中執行adb shell命令的方式如下:

/**
* 執行一個shell命令,並返回字元串值
*
* @param cmd
* 命令名稱&參數組成的數組(例如:{"/system/bin/cat", "/proc/version"})
* @param workdirectory
* 命令執行路徑(例如:"system/bin/")
* @return 執行結果組成的字元串
* @throws IOException
*/
public static synchronized String run(String[] cmd, String workdirectory)
throws IOException {
StringBuffer result = new StringBuffer();
try {
// 創建操作系統進程(也可以由Runtime.exec()啟動)
// Runtime runtime = Runtime.getRuntime();
// Process proc = runtime.exec(cmd);
// InputStream inputstream = proc.getInputStream();
ProcessBuilder builder = new ProcessBuilder(cmd);
InputStream in = null;
// 設置一個路徑(絕對路徑了就不一定需要)
if (workdirectory != null) {
// 設置工作目錄(同上)
builder.directory(new File(workdirectory));
// 合並標准錯誤和標准輸出
builder.redirectErrorStream(true);
// 啟動一個新進程
Process process = builder.start();
// 讀取進程標准輸出流
in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
result = result.append(new String(re));
}
}
// 關閉輸入流
if (in != null) {
in.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result.toString();
}

android系統底層採用的是linux,所以adb這樣的linux指令是可以在java代碼中調用的,可以使用ProcessBuilder 這個方法來執行對應的指令。還可以通過如下方式執行:

Process p = Runtime.getRuntime().exec("ls");
String data = null;
BufferedReader ie = new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String error = null;
while ((error = ie.readLine()) != null
&& !error.equals("null")) {
data += error + "\n";
}
String line = null;
while ((line = in.readLine()) != null
&& !line.equals("null")) {
data += line + "\n";
}

Log.v("ls", data);

2. 如何用shell命令打開某個手機app

android中執行shell命令有兩種方式:1.直接在代碼中用java提供的Runtime這個類來執行命令,以下為完整示例代碼。publ

閱讀全文

與安卓mkshell命令相關的資料

熱點內容
周末程序員吃什麼 瀏覽:996
解壓的pdf格式怎麼轉換 瀏覽:228
ad輸出pdf 瀏覽:306
dhcp伺服器如何部署 瀏覽:508
如何追女生app 瀏覽:432
阿里雲域名綁定香港伺服器 瀏覽:551
java文本文件壓縮 瀏覽:531
心靈解壓大笑視頻 瀏覽:600
東學西學單片機 瀏覽:671
phpstudy做伺服器如何使用 瀏覽:952
平板怎麼下載安卓國服 瀏覽:775
源碼時代找不到工作會退錢嗎 瀏覽:214
如何app搭建伺服器 瀏覽:846
javastringblob 瀏覽:297
王瑤pdf 瀏覽:859
開掛軟體顯示請連接伺服器地址 瀏覽:917
蘋果怎麼下載安卓倩女 瀏覽:586
vip藍光視頻解析網站源碼 瀏覽:942
伺服器ps1ps2是什麼意思 瀏覽:858
seo命令 瀏覽:869