更新Termux应用打开方法
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Apr 30 09:29:52 CST 2026
|
||||
#Thu Apr 30 01:57:42 GMT 2026
|
||||
stageCount=26
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.25
|
||||
buildCount=38
|
||||
buildCount=42
|
||||
baseBetaVersion=15.11.26
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MyTermuxActivity extends AppCompatActivity {
|
||||
|
||||
private void executeSampleCommand() {
|
||||
if (isTermuxAvailable()) {
|
||||
boolean success = TermuxCommandExecutor.executeTerminalCommand(this, "ls -la /data/data/com.termux/files/home");
|
||||
boolean success = TermuxCommandExecutor.openTermuxBash(this, "ls -la ./");
|
||||
if (success) {
|
||||
LogUtils.i(TAG, "命令执行成功");
|
||||
} else {
|
||||
@@ -71,4 +71,4 @@ public class MyTermuxActivity extends AppCompatActivity {
|
||||
private boolean isTermuxAvailable() {
|
||||
return TermuxCommandExecutor.isTermuxInstalled(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class TermuxCommandExecutor {
|
||||
// Termux RunCommandService 完整类名(包名+类名)
|
||||
private static final String TERMUX_RUN_CMD_SERVICE_CLASS = "com.termux.app.RunCommandService";
|
||||
private static final String TERMUX_RUN_CMD_ACTION = TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND;
|
||||
private static final String TERMUX_HOME_PATH = "/data/data/com.termux/files/home";
|
||||
|
||||
/**
|
||||
* 执行 Termux 命令(核心方法)
|
||||
@@ -173,5 +174,42 @@ public class TermuxCommandExecutor {
|
||||
LogUtils.d(TAG, "外部应用调用权限提示:" + tip);
|
||||
return tip;
|
||||
}
|
||||
|
||||
public static boolean openTermuxBash(Context context, String command) {
|
||||
LogUtils.d(TAG, "openTermuxBash() 按钮点击,执行Gradle命令(实时输出)");
|
||||
|
||||
// 1. 校验Termux是否安装
|
||||
if (!TermuxCommandExecutor.isTermuxInstalled(context)) {
|
||||
LogUtils.e(TAG, "openTermuxBash() 错误:未安装Termux应用");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 定义核心路径(确保路径与Termux中一致)
|
||||
String projectPath = TERMUX_HOME_PATH + "/"; // 项目目录
|
||||
|
||||
// 3. 构造命令(核心:用stdbuf禁用缓冲,实现实时输出)
|
||||
String targetCmd = "";
|
||||
// 步骤1:进入项目目录(不存在则创建)
|
||||
targetCmd += "cd " + projectPath + " && ";
|
||||
// 步骤2:加载环境变量
|
||||
targetCmd += "source ~/.bashrc && ";
|
||||
// 步骤3:显式配置PATH
|
||||
targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:$PATH && ";
|
||||
// 步骤4:用stdbuf禁用stdout/stderr缓冲(关键!),执行Gradle命令
|
||||
// -o0:stdout无缓冲;-e0:stderr无缓冲;-i0:stdin无缓冲
|
||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " task --all | grep assemble && ";
|
||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " -Pandroid.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 assembleBetaDebug && ";
|
||||
targetCmd += "stdbuf -o0 -e0 -i0 bash && ";
|
||||
// 步骤5:执行成功提示
|
||||
targetCmd += "echo '\n✅ 命令执行完成!' && echo '\n📌 当前目录:" + projectPath + "' && read -p '按回车键关闭终端...'";
|
||||
|
||||
|
||||
// 4. 执行命令(终端会话模式,唤起Termux窗口)
|
||||
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(context, targetCmd);
|
||||
if (!cmdSuccess) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user