与Android的应用程序运行脚本 [英] Run script with android app
问题描述
我有了这个shell脚本:
i've got this shell script:
#!system/bin/sh
while :
do
sync
echo 3> /proc/sys/vm/drop_caches
echo "Script is been launched"
sleep 30m
done
exit 0;
我想运行此脚本一个Android应用程序。我已经创建了一个按钮,只举杯现在。我怎样才能把脚本(free.sh),并与该应用程序的按钮启动它?还是有一个解决方案,以改写code在java吗?谢谢
i wish run this script with an android app. I have already created a button with only a toast for now. How can i take the script (free.sh) and launch it with the button on the app? Or is there a solution to rewrite the code in java? Thanks
推荐答案
首先,您将使用Eclipse来创建一个简单的Android的HelloWorld应用程序。 而在布局中添加一个按钮。这是Android的发展非常孙昌盛的做法,你可以挖了很多从 http://d.android.com
First, you will use Eclipse to create a simple Android helloworld app. And add a button in your layout. This is very priliminary practise of Android development which you can dig a lot more from http://d.android.com
请试试这个code在按钮的onclick回调函数:
please try this code in your button's onclick call back function:
Button b = (Button)findViewById(R.id.buttonPower);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Process p=null;
try {
p = new ProcessBuilder()
.command("PathToYourScript")
.start();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(p!=null) p.destroy();
}
}
});
这篇关于与Android的应用程序运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!