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;
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
1. On the SureMDM Web Console, navigate to Jobs > New Job > Android > Run Script. 2. In the Run Script prompt, enter a Job Name, Script and click Save.
Even though your device is rooted, android environment won't allow applications to execute 'sh' commands. As android security architecture says, applications run within a secured execution space inside Application Sandbox, sh execution can bypass this security.
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
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();
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With