简体   繁体   English

如何在我的 Android 应用程序中运行 Linux 命令?

[英]How to run Linux commands in my Android app?

I want to run a Linux command in my Android app.我想在我的 Android 应用程序中运行 Linux 命令。 I mean I'm an Android programmer and I want to commit a command in my codes in Java which I'm writing in Android Studio.我的意思是我是一名 Android 程序员,我想在我在 Android Studio 中编写的 Java 代码中提交一个命令。

For example this is what I want in my codes in Java in Android Studio:例如,这就是我在 Android Studio 中的 Java 代码中想要的:

ImaginarylinuxClass.theFunctionWhichRunsTheCommands("sudo apt-get update && git clone  && etc");

I hope I was able to say what I mean.我希望我能说出我的意思。

I tried to Google about it but it was all apps which they are Linux emulators like termux but it's not what I want actually.我试着用谷歌搜索一下,但所有的应用程序都是 Linux 模拟器,比如termux,但这并不是我真正想要的。

Test this code man:测试这个代码人:

try {
    Runtime.getRuntime().exec("cd sdcard/");
} catch (Exception e) {
    showMessage(e.toString());
}

Replace "cd sdcard/" for your Linux commands...“cd sdcard/”替换为您的 Linux 命令...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM