0

There is an app capture screen when shark android phone .

1)when app on active , capture screen without root .

2)when app back to stack , like return HOME, need root permission to capture screen .

i want to know the implement the function 2) with root permission .

in my mind, root permission means get a root shell, flush some command and exec . so i confuse how to capture screen in shell command .

fazhang
  • 485
  • 6
  • 13

1 Answers1

1

If you have root or even shell permission, you can use either screenshot or screencap command, for your reference:

root@android:/system/bin # screenshot -h                                   
unknown option -- husage: screenshot [-s soundfile] filename.png
   -s: play a sound effect to signal success
   -i: autoincrement to avoid overwriting filename.png

root@android:/system/bin # screencap -h                                      
    usage: screencap [-hp] [-d display-id] [FILENAME]
       -h: this message
       -p: save the file as a png.
       -d: specify the display id to capture, default 0.
    If FILENAME ends with .png it will be saved as a png.
    If FILENAME is not given, the results will be printed to stdout.

If your device does not have these program in native, you can simply write one by yourself. The source code is here: https://android.googlesource.com/platform/frameworks/base/+/master/cmds/screencap/screencap.cpp

Robin
  • 10,052
  • 6
  • 31
  • 52
  • Thanks a lot , and I find an another solution . chmod /dev/graphics/fb0 – fazhang Aug 26 '13 at 09:11
  • That's not a good idea to change the device permission. But you can stick to whatever solution you feel comfortable. However, my question is that if you just have the permission to access the frame buffer, you still need to do the image encoding by yourself. But these tasks are all handled in the screencap which will save you a lot of effort. I highly recommend you to accept my answer. – Robin Aug 26 '13 at 09:13
  • Yes . and I read the screencap.cpp , this file through read the device file to capture screen . that chmod idea works in version 2.3 or older version . Thank You Very Much . – fazhang Aug 26 '13 at 09:15