English 中文(简体)
重新启动和机器人电话(模拟器)?
原标题:Restart android phone (emulator)?

我想在按下按钮时重新启动移动。 为此我写了这些...

        PowerManager pm;
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);        
           pm = (PowerManager) getSystemService(Context.POWER_SERVICE);        
           Button test = (Button) findViewById(R.id.button1);

           test.setOnClickListener(new OnClickListener() {          
        public void onClick(View v) {

            try {
                Process proc = Runtime.getRuntime().exec(new String[] {"su", "-c", "reboot" });

                            int result = proc.waitFor();
                Toast.makeText(ForTestActivity.this, "INt:"+result, Toast.LENGTH_SHORT).show();


            } catch (Exception ex) {
                Log.i("XXXXXXXXXXXX", "Could not reboot", ex);
            }

        }
    });

} 

This is not working in emulator.I m using android2.3.3 for develop this application. It does not give any errors and nothing happened after I press the button. The toast was displaying result as 1.

之后我也尝试了这个代码...

     Process p = Runtime.getRuntime().exec("su");
                DataOutputStream os = new DataOutputStream(p.getOutputStream());            
                os.writeBytes("reboot"+"
");                             
                os.writeBytes("exit
");  
                os.flush(); 

同样的结果。 我也添加了必要的权限。 有人知道吗?

[在按下按钮后,我想重新启动(或关闭)电话。 ]

最佳回答

你试过没有"su -c"的"su -c"的"su -c"命令吗?

当我输入“adb shell reputt” 我的手机重新启动时( 但我的手机是“ 坚固的” / 坚固的 < / 坚固的 < / 坚固的 ”, 这在本案中是必要的 ), 因此我认为如果您只是执行代码中的“ 重新启动 ”, 效果应该是相似的。 我认为“ su - c” 是不必要的, 因为您已经在根线手机上拥有根权( IMRC 模拟器因默认而根植 ) 。

正如其他发言者提到的那样,这不会在不固定的电话上起作用。

问题回答

问了一个类似的问题,回答的答案是





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......