如何在启动时设置运行时(echo)命令?
有人可以帮助我如何设置这个 echo 命令,您可以在下面看到启动采用时的命令(因为当我只使用按钮执行它时,所以重新启动后会再次出现默认值)?我知道如何使用 BroadcastReceiver 实现这一点,但我有更多按钮,每个按钮都包含一个 echo 命令,我只需要最后单击的按钮,并在启动采用时设置 echo 命令。
这里是示例:
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
Button b=(Button)findViewById(R.id.btn_button);
b.setOnClickListener(new OnClickListener(){
public void onClick(View paramView){
Process b;
try {
b = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(b.getOutputStream());
os.writeBytes("echo '1,1,1,1,1,1' > /sys/module/lowmemorykiller/parameters/minfree\n");
os.writeBytes("exit\n");
os.flush();
try {
b.waitFor();
if (b.exitValue() != 255) {
// TODO Code to run on success
toastMessage("root");
}
else {
// TODO Code to run on unsuccessful
toastMessage("not root");
}
} catch (InterruptedException e) {
// TODO Code to run in interrupted exception
toastMessage("not root");
}
} catch (IOException e) {
// TODO Code to run in input/output exception
toastMessage("not root");
}
}
});
}
谢谢。
Could anybody help me how can I set this echo command which you can see below on boot adoption (because when I only execute it with button so after restart there are default values again)? I know how make it with BroadcastReceiver, but I have more buttons and each button contains one echo command and I need only last clicked button with echo command set on boot adoption.
Here is example:
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
Button b=(Button)findViewById(R.id.btn_button);
b.setOnClickListener(new OnClickListener(){
public void onClick(View paramView){
Process b;
try {
b = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(b.getOutputStream());
os.writeBytes("echo '1,1,1,1,1,1' > /sys/module/lowmemorykiller/parameters/minfree\n");
os.writeBytes("exit\n");
os.flush();
try {
b.waitFor();
if (b.exitValue() != 255) {
// TODO Code to run on success
toastMessage("root");
}
else {
// TODO Code to run on unsuccessful
toastMessage("not root");
}
} catch (InterruptedException e) {
// TODO Code to run in interrupted exception
toastMessage("not root");
}
} catch (IOException e) {
// TODO Code to run in input/output exception
toastMessage("not root");
}
}
});
}
THANK YOU.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题有点不清楚,但据我所知,广播是设计的方法。这需要您从接收 BOOT_COMPLETE 广播的服务启动您的活动。
您可以像这样从您的服务启动一个活动:
您可以将该活动绑定到您的服务,或者将您的“echo”代码移动到静态助手中以保持整洁。
或者,如果您希望将活动作为启动器运行,您可以使用
,但这可能不是您想要的解决方案。
The question is slightly unclear but from what I can comprehend broadcast is the designed method. This would require that you launch your activity from the service receiving the BOOT_COMPLETE broadcast.
You can launch an activity from your service like this:
You could either bind the activity to your service or move your "echo" code into a static helper to keep it tidy.
Alternatively if you wish to run your activity as a launcher you can use
but that may not be your inteded solution.