[英]How set runtime (echo) command on boot adoption?
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)? 有人可以帮我如何设置这个echo命令,您可以在启动采用时在下面看到(因为当我仅使用按钮执行该命令时,所以在重启后再次有默认值)? 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. 我知道如何使用BroadcastReceiver做到这一点,但是我有更多按钮,并且每个按钮都包含一个echo命令,并且我只需要在启动采用时设置了echo命令的最后单击按钮即可。
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. 谢谢。
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. 这将要求您从接收BOOT_COMPLETE广播的服务中启动活动。
You can launch an activity from your service like this: 您可以像这样从服务启动活动:
Intent intent = new Intent(MyService.this,MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
You could either bind the activity to your service or move your "echo" code into a static helper to keep it tidy. 您可以将活动绑定到您的服务,也可以将“ echo”代码移到静态帮助器中以使其保持整洁。
Alternatively if you wish to run your activity as a launcher you can use 或者,如果您希望以启动器的形式运行活动,则可以使用
<category android:name="android.intent.category.LAUNCHER" />
but that may not be your inteded solution. 但这可能不是您想要的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.