導航:首頁 > 程序命令 > 安卓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命令相關的資料

熱點內容
雜的文pdf 瀏覽:320
蕪湖公交app怎麼了 瀏覽:596
安卓手機聽書怎麼快捷 瀏覽:768
fpga脈沖壓縮 瀏覽:910
安卓平板qq壓縮文件怎麼解壓 瀏覽:539
安卓電子郵件怎麼添加 瀏覽:927
linux伺服器多個網站 瀏覽:97
我的世界伺服器如何做公告欄 瀏覽:94
長城超雲伺服器怎麼安裝系統 瀏覽:606
文件夾不能正反面列印怎麼回事 瀏覽:847
中聯攪拌站資料庫在哪個文件夾 瀏覽:535
巧遇app怎麼加人微信 瀏覽:597
雲伺服器二層互聯 瀏覽:810
單片機兩路模擬采樣 瀏覽:885
如何把舊電腦變成伺服器 瀏覽:165
linuxtimestamp 瀏覽:824
pdf有白邊 瀏覽:512
linux內核文件路徑 瀏覽:305
csgo國際服雲伺服器 瀏覽:919
stata回歸命令vce是啥 瀏覽:569