android系统运行于Dalvik VM中,有着与Linux雷士的Shell Command指令,可通过Runtime().getRuntime().exec()来运行指令。
下面我们就通过代码来实现这一功能,体验一下命令行。
1.activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/et_input"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="4dp"
android:hint="Input Command Lines" />
<Button
android:id="@+id/btn_run"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_input"
android:text="Run" />
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="match_parent"