Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android应用程序中获取at命令的答案_Android_Shell_At Command_Su - Fatal编程技术网

在android应用程序中获取at命令的答案

在android应用程序中获取at命令的答案,android,shell,at-command,su,Android,Shell,At Command,Su,首先,我的手机是扎根的。我敢肯定,因为我尝试了几种方法来了解这一点。其中一种方法是根检查器基本应用程序 我将此代码放入一个应用程序中并尝试,一切正常: Process p; try { // Preform su to get root privledges p = Runtime.getRuntime().exec("su"); // Attempt to write a file to a root-only DataOutputStre

首先,我的手机是扎根的。我敢肯定,因为我尝试了几种方法来了解这一点。其中一种方法是根检查器基本应用程序

我将此代码放入一个应用程序中并尝试,一切正常:

Process p;   
try {   
   // Preform su to get root privledges  
   p = Runtime.getRuntime().exec("su");   

   // Attempt to write a file to a root-only   
   DataOutputStream os = new DataOutputStream(p.getOutputStream());   
   os.writeBytes("echo \"Do I have root?\" >/storage/extSdCard/temp.txt\n");  

   // Close the terminal  
   os.writeBytes("exit\n");   
   os.flush();   
   try {   
      p.waitFor();   
           if (p.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");   
}  
toastMessage只是一个函数,用于获取答案“root”。 但是当我在这段代码中做了一些更改以读取at命令的答案时,应用程序停止了,没有得到任何响应

    Process p;   
    try {   
       // Preform su to get root privledges  
       p = Runtime.getRuntime().exec("su");   

       // Attempt to write a file to a root-only   
       DataOutputStream os = new DataOutputStream(p.getOutputStream());   
       os.writeBytes("echo \"AT+CQI?\"\n");  

       BufferedReader reader = new BufferedReader(
               new InputStreamReader(p.getInputStream()));
       int read;
       char[] buffer = new char[4096];
       StringBuffer output = new StringBuffer();
       while ((read = reader.read(buffer)) > 0) {
           output.append(buffer, 0, read);
       }
       reader.close();
       try {
        p.waitFor();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
       tv.setText(output.toString());


       // Close the terminal  
       os.writeBytes("exit\n");   
       os.flush();   

    } catch (IOException e) {   
       // TODO Code to run in input/output exception  
        tv.setText("not root");   
    }
电视是一种文本视图

我犯了什么错误
我尝试了很多方法来读取at命令的答案,但问题总是在读取中。

尝试添加一些断点,看看它在哪里卡住。因为我在手机上实现了这个应用,我不知道如何添加断点,除非它将在模拟器上运行。。。我试着删除一些代码,比如while和wait,当我删除两个应用程序运行时,但是当然没有得到答案。它在模拟器上不能像在手机上那样工作。模拟器中的答案不是根。在手机中时(根本没有响应)。这就是为什么我不能添加断点。你可以在手机上设置断点,方法与在模拟器中相同