I need to execute a C program in my App by simply adding the executable to the android project and building the .apk. Then I try to execute the program in my application like this:
Process result = Runtime.getRuntime().exec("su");
String cmd = "PROGRAM_NAME";
DataOutputStream dos = new DataOutputStream(result.getOutputStream());
DataInputStreamdis = new DataInputStream(result.getInputStream());
dos.writeBytes(cmd + "\n");
dos.writeBytes("exit\n");
dos.flush();
I know I need root access to do this so I installed Superuser.apk but that didn't work. Is there another possible way to do this? Btw the code is not fully extended it should just give a look at the way the program should be executed I'm running the emulator with Android 4.2.1
Edit: Checking root permission first with
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
DataInputStream osRes = new DataInputStream(suProcess.getInputStream());
if (null != os && null != osRes) {
os.writeBytes("id\n");
os.flush();
String currUid = osRes.readLine();
boolean exitSu = false;
if (null == currUid) {
Log.d("ROOT", "Can't get root access or denied by user");
}