Call screenrecord within android app on samsung device not working

339 views Asked by At

I am using the screenrecord api from android within my app.

Therefor i have read several good postings

On a rooted Nexus 5 (Android 5.1) the code below works without any problems. That means that the screen record gets triggered and the video is saved succesfully to the sdcard.

On a rooted Samsung S6 Edge (Android 5.0.2) the code will stuck at the first call of readLine(). The mp4 file is created and can be found on the sdcard but it is empty.

Permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

Here my code:

try {
    Process process = Runtime.getRuntime().exec("su");
    OutputStream stdin = process.getOutputStream();

    InputStream stderr = process.getErrorStream();
    InputStream stdout = process.getInputStream();

    stdin.write(("/system/bin/screenrecord --time-limit 10 /sdcard/recording.mp4\n").getBytes());

    stdin.write("exit\n".getBytes());

    stdin.flush();   //flush stream
    stdin.close(); //close stream

    String line;
    BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
    while ((line = br.readLine()) != null) {
        Log.i("Response: ", line);
        mResults.append(line);
    }
    br.close();

    br = new BufferedReader(new InputStreamReader(stderr));
    while ((line = br.readLine()) != null) {
        Log.e("Error: ", line);
        mErrors.append(line);
    }
    br.close();

} catch(IOException ioe) {
    Log.e(TAG, "IOException: " + ioe.toString());
}

So I searched the web and found out that it might be the problem that there is just nothing to be read. I added "&& echo done" to the shell command but still no change.

I checked the log several times and I found two lines with KNOX in it:

I/libpersona﹕ KNOX_SDCARD checking this for 10202

I/libpersona﹕KNOX_SDCARD not a persona

I thought maybe KNOX prevents my app from writing to the sdcard. So I deleted KNOX from the device but the same problem still occurred.

I need to get this code running on this particular Samsung device. Hopefully some of you have an idea how to get the code running.

Thanks Daniel

1

There are 1 answers

0
Failster On

I haven't found a solution for the described particular problem. But I stumbled over another API that helped me to achieve my goal and record the screen of an android device.

With the help of the MediaRecorder and the VirtualDisplay I was able to capture the screen into a mp4-file onto the sdcard.