0

I'm trying to programmatically execute the new command "ScreenRecorder" kitkat. I just tried this:

suProcess = Runtime.getRuntime().exec("su");
process = Runtime.getRuntime().exec("screenrecord /sdcard/Folder/Example.mp4");

But doesn't work. In the Folder I've the file Example.mp4 but it is empty (0 byte). Why? How can I solve this? Where is the problem? If from terminal emulator I write su and press enter and after write screenrecord /sdcard/Folder/Example.mp4 it works perfectly. Obvisioully I'm running on 4.4.2 and in a rooted terminal.

twlkyao
  • 14,302
  • 7
  • 27
  • 44
Giovanni Mariotti
  • 615
  • 1
  • 7
  • 11
  • 1
    This way, su is executed independendly from screenrecord – deviantfan Dec 31 '13 at 10:07
  • Is your device rooted? – Aman Arora BB Dec 31 '13 at 10:07
  • AmanAroraBB Yes, my device is rooted. Read well my question please. @deviantfan So I should do something like? process = Runtime.getRuntime().exec("su"); process = Runtime.getRuntime().exec("screenrecord /sdcard/Folder/Example.mp4"); – Giovanni Mariotti Dec 31 '13 at 10:10
  • 1
    If your version of `su` takes a command as arguments (i.e. it works like `sudo`), then you would use `su screenrecord /sdcard/Folder/Example.mp4`. Keep an eye on logcat for failure messages. – fadden Dec 31 '13 at 16:14

2 Answers2

1

Try this

public static void ScreenRecord() throws Exception
    {
        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);
        }
    }
Xar-e-ahmer Khan
  • 1,314
  • 15
  • 23
0

It doesn't work because it's an emulator and not a normal device. I think this article could help in this case: http://russelldavis.blogspot.com/2011/01/rooting-android-emulator.html

XorOrNor
  • 8,868
  • 12
  • 48
  • 81
  • I'm running the application in Runtime on an Android device, not the emulator. With mean terminal emulator i meant the application available in Google Play Store. – Giovanni Mariotti Dec 31 '13 at 10:14