Android calls Screenrecord to implement recording screen

Source: Internet
Author: User

First of all to illustrate is not achieved, this article to talk about their own ideas.

ADB uses the shell command to screenrecord a recordable screen. I wrote an app that called the shell command through the process P = runtime.getruntime (). exec (cmd), error:
Java.lang.SecurityException:Permission Denial:broadcast asks to run as user-2 it calling from user 0

Requires Android.permission.INTERACT_ACROSS_USERS_FULL or Android.permission.INTERACT_ACROSS_USERS permissions, which is the permissions of the system app , third-party apps do not have permission to apply.

Therefore, 4.4 of the recording screen is required root authority. After 5.0, the Mediaprojection API does not require root privileges (which allows ordinary, unprivileged applications to record of the screen). Using the verbose parameter, a broadcast will be sent to tell the system that a new file has been generated when the recording screen finishes:
[Email Protected]:/sdcard $ screenrecord--verbose--time-limit 10/SDCARD/1. Mp4main Display is0x1280 @59.00fps (orientation=0) Configuring Recorder for720x1280 VIDEO/AVC at 4. 00MbpsContent Area is0x1280 at offset x=0 y=0Time limit reachedencoder stopping; recorded6 Frames in 10secondsstopping encoder and muxerexecuting:/system/bin/am Broadcast-a Android.intent.action.MEDIA_SCANNER_SCAN_FILE-D File:///sdcard/1.mp4broadcasting:intent {act=android.intent.action.media_scanner_scan_file dat= file:///sdcard/1.mp4}Broadcast completed:result=0

So take a look at the Screenrecord source bar.

Frameworks\av\cmds\screenrecord\screenrecord.cpp New video.  is Optional. */static status_t notifymediascanner (constChar* fileName) really has such a function, and then in main This function is called at the end of the function:if (err = = no_error) {    //  Try to notify the media scanner. Not fatal if this fails.     Notifymediascanner (fileName);}

So, if you comment out Notifymediascanner (fileName); This line, recompile the Screenrecord executable program in the recording screen will not broadcast, is not without root permission?
After testing, it is possible.

Modify the source code, recompile the framework (in fact, I am compiling the entire source code, the framework does not generate a separate Screenrecord executable), and then replace the system/bin/under the Screenrecord (this operation requires root permissions, so this article is only for research, and does not achieve the root-free use of Screenrecord recorder screen. Of course, if you do ROM, you can just pack the Screenrecord into it, and then you can do it without root privileges. But the screen result is empty file (size 0 KB), debug information as follows: ... Time limit Reachedencoder stopping; Recorded 0 frames in 3 secondsstopping encoder and Muxer ... Continue to view screenrecord.cpp, cancel #define LOG_NDEBUG 0 comment on this line, that is, open ALOGV switch, recompile, replace the Screenrecord in the phone, the app calls the Screenrecord command again, the log is as follows :

C:\USERS\WY>ADB Logcat | findstr/i "Screenrecord"
10-17 10:36:17.435 9839 9839 V screenrecord:creating codec
10-17 10:36:17.531 9839 9839 V screenrecord:creating Encoder Input Surface
10-17 10:36:17.533 9839 9839 V screenrecord:starting codec
10-17 10:36:17.618 9839 9839 V Screenrecord:codec prepared
10-17 10:36:17.623 9839 9839 V screenrecord:calling dequeueoutputbuffer
10-17 10:36:17.873 9839 9839 V screenrecord:dequeueoutputbuffer returned-11
10-17 10:36:17.873 9839 9839 V screenrecord:got-eagain, looping
10-17 10:36:17.873 9839 9839 V screenrecord:calling dequeueoutputbuffer
10-17 10:36:18.124 9839 9839 V screenrecord:dequeueoutputbuffer returned-11
10-17 10:36:18.124 9839 9839 V screenrecord:got-eagain, looping
10-17 10:36:18.124 9839 9839 V screenrecord:calling dequeueoutputbuffer

The log shows that the error has been returned at the time of buffer output, and repeated attempts have been made until the end of the screen has not been successfully recorded.

I don't know why, but I have to look at the code.

First lost here, hope to understand the great God guidance.


Android calls Screenrecord to implement recording screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.