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.
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 = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); process.waitFor(); 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.
Comments
Post a Comment