[英]How set runtime (echo) command on boot adoption?
有人可以幫我如何設置這個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");
}
}
});
}
謝謝。
這個問題還不太清楚,但是據我所知,廣播是設計好的方法。 這將要求您從接收BOOT_COMPLETE廣播的服務中啟動活動。
您可以像這樣從服務啟動活動:
Intent intent = new Intent(MyService.this,MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
您可以將活動綁定到您的服務,也可以將“ echo”代碼移到靜態幫助器中以使其保持整潔。
或者,如果您希望以啟動器的形式運行活動,則可以使用
<category android:name="android.intent.category.LAUNCHER" />
但這可能不是您想要的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.