如何在android上编写简单的脚本

如何在android上编写简单的脚本,android,bash,Android,Bash,是否可以在Android终端上运行简单的脚本? 我想运行以下命令 $su $cd /Downloads 是,在应用商店中搜索终端仿真器 试试这样的方法: try{ Process su = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); outputStream.writeBytes("scr

是否可以在Android终端上运行简单的脚本? 我想运行以下命令

$su
$cd /Downloads

是,在应用商店中搜索终端仿真器

试试这样的方法:

    try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("screenrecord --time-limit 10 /sdcard/MyVideo.mp4\n");
    outputStream.flush();

    outputStream.writeBytes("exit\n");
    outputStream.flush();
    su.waitFor();
}catch(IOException e){
    throw new Exception(e);
}catch(InterruptedException e){
    throw new Exception(e);
}
也请阅读这篇文章