Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public String ls () { Class&lt;?&gt; execClass = Class.forName("android.os.Exec"); Method createSubprocess = execClass.getMethod("createSubprocess", String.class, String.class, String.class, int[].class); int[] pid = new int[1]; FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(null, "/system/bin/ls", "/", null, pid); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fd))); String output = ""; try { String line; while ((line = reader.readLine()) != null) { output += line + "\n"; } } catch (IOException e) {} return output; } </code></pre> <p>Check this code mentioned here:</p> <p><a href="https://stackoverflow.com/questions/2843250/how-to-run-terminal-command-in-android-application/2843274#2843274">How to run terminal command in Android application?</a></p> <hr> <pre><code>try { // Executes the command. Process process = Runtime.getRuntime().exec("/system/bin/ls /sdcard"); // Reads stdout. // NOTE: You can write to stdin of the command using // process.getOutputStream(). BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) &gt; 0) { output.append(buffer, 0, read); } reader.close(); // Waits for the command to finish. process.waitFor(); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } </code></pre> <hr> <p><strong>References</strong></p> <p><a href="http://gimite.net/en/index.php?Run%20native%20executable%20in%20Android%20App" rel="nofollow noreferrer">this code</a> <a href="http://forum.xda-developers.com/showthread.php?t=486486" rel="nofollow noreferrer">GScript</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload