Run native binary executable from Android app

If you wan to run a native binary Linux executable from your Android app you can use this ready-made function. The only param is the command line to execute.

Basically this function get as param the full command line composed by the binary executable name and, if any, the command line params (for example '/system/bin/ls /sdcard'). Return the exit value number generated by executed binary and redirect all the console output of this same executable to the logcat tool.

int executeCommandLine(String commandLine)
     try {
            Process process = Runtime.getRuntime().exec(commandLine);            

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuffer output = new StringBuffer();
            char[] buffer = new char[4096];
            int read;

            while ((read = > 0) {
                output.append(buffer, 0, read);



            Log.d("executeCommandLine", output.toString());

            return process.exitValue();
        } catch (IOException e) {
            throw new RuntimeException("Unable to execute '"+commandLine+"'", e);
        } catch (InterruptedException e) {
            throw new RuntimeException("Unable to execute '"+commandLine+"'", e);

Hope this help.


Popular posts from this blog

Access GPIO from Linux user space

Launch an app from Android shell terminal

Android: adb push and read-only file system error