Android take screenshot (ROOT)

999 views Asked by At

I am developing an app for taking screenshots with root access. I am using this call to take screenshot:

"/system/bin/screencap -p " + getFilesDir() + "screen.png"

However it creates this screenshot in root context and I can't access it with my app even if I chmod 777 and chown user_id:user_id. SELinux still says that this access is denied because scontext is u:r:untrusted_app:s0 while tcontext is u:object_r:app_data_file:s0. I have tried calling su with --context u:r:untrusted_app:s0 but it didn't help.

Any idea on how to perform correct screen capture call which will save it to app internal storage and then allow access for app?

1

There are 1 answers

0
Robert On

If you have accessing the file because of permissions you can remove the -p <filename> part of the command. In this case the created image will be piped to stdout which is definitely accessible by your app. You just have to connect to the InputStream of the Process executing the su comand and save the data yourself to a file or use it in your app.

How to read Stdout if shown here: Read command output inside su process Note that in this example the asker wants to read text, hence the accepted solution reads data to a buffer and converts to a String - of course you don't need the conversion as the PNG file is not a printable String...