I am trying to start a service of an another app (not mine) from command line in my Android app. But I've noticed that it works only if I run "su". My phone of course is "rooted". Maybe there is another way to start a service of an app without needing to execute a shell command?
This code works:
try {
Process process = Runtime.getRuntime().exec("su", null,null);
OutputStream outputStream = process.getOutputStream();
outputStream.write(("am startservice -a com.companyname.notmyapp.TEST --option a 1").getBytes("ASCII"));
outputStream.flush();
outputStream.close();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
This one it doesn't:
try {
Process process = Runtime.getRuntime().exec("am startservice -a com.companyname.notmyapp.TEST --option a 1", null,null);
//OutputStream outputStream = process.getOutputStream();
//outputStream.flush();
//outputStream.close();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}