I'm trying to execute this command from the application emulator terminal (you can find it in google play) in this app i write su
and press enter, so write:
screenrecord --time-limit 10 /sdcard/MyVideo.mp4
and press again enter and start the recording of the screen using the new function of android kitkat.
so, i try to execute the same code from java using this:
Process su = Runtime.getRuntime().exec("su"); Process execute = Runtime.getRuntime().exec("screenrecord --time-limit 10 /sdcard/MyVideo.mp4");
But don't work because the file is not created. obviously i'm running on a rooted device with android kitkat installed. where is the problem? how can i solve? because from terminal emulator works and in Java not?
Open the Command Shell on an Remote Endpoint Using the Android Access Console. Remote command shell enables privileged users to open a virtual command line interface on remote computers. Users can then type locally but have the commands executed on the remote system. You can work from multiple shells.
During VTS testing, shell commands are used to execute a target-side test binary, to get/set properties, environment variables, and system information, and to start/stop the Android framework.
Start by creating a Shell: val shell = Shell("sh") ``` Then invoke the `run()` method passing in shell command you want executed as a string: ```kotlin val result = shell. run("echo 'Hello, World! '")
You should grab the standard input of the su
process just launched and write down the command there, otherwise you are running the commands with the current UID
.
Try something like this:
try{ Process su = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); outputStream.writeBytes("screenrecord --time-limit 10 /sdcard/MyVideo.mp4\n"); outputStream.flush(); outputStream.writeBytes("exit\n"); outputStream.flush(); su.waitFor(); }catch(IOException e){ throw new Exception(e); }catch(InterruptedException e){ throw new Exception(e); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With