Android App internal monitoring screenshot plus QR code function code

Android screenshot function is a common function that can be easily shared or sent to friends. This paper introduces how to realize the screenshot monitoring function in the app. When users are found to have screenshots in our app, they can carry out secondary operations on pictures, such as adding QR code, company logo, etc.

Project address

Test screenshot:

Screenshot principle

The Android system does not provide the API related to screenshot notification. We need to make use of the relevant features provided by the system. The Android system has a media database. Every time a photo is taken or a picture is captured using the system screenshot, the details of the picture will be added to the media database and a content change notice will be sent. We can use the content observer to monitor the changes of the media database. When the database changes, Get the last inserted picture data. If the picture meets specific rules, it is considered to be screenshot.

Judgment basis

When contentobserver listens to the data change in the media database, it obtains the last picture data inserted into the database when there is a data change. If the following rules are met, it is considered that the screen capture is complete:

These judgments are to increase the reliability of screen capture detection results, prevent false positives and prevent omissions. The path of the screenshot image is in the normal path format saved by the Android system. For example, mine is: "external memory / storage / emulated / 0 / pictures / screenshots / screenshot_2017-08-03-15-42-58. PNG". However, the Android system is seriously fragmented and other third-party screenshot apps are added. Therefore, in addition to checking whether the path keyword contains "screenshot", You can also add other keywords appropriately. See the complete code of the listener at the end for details. This method of monitoring screenshots is not 100% accurate. For example, some root machines use a third-party screenshot app to customize the save path. For example, they can't monitor the screenshots of mobile phones obtained on the computer through ADB command, but this is also the most feasible method at present, which is more reliable for most users.

Code description

Monitor screenshot

Global use

Our requirement is to monitor screenshots globally in the app, so we only need to monitor in baseactivity.

So far, the screen capture operation of monitoring in app is completed. We need to monitor and perform corresponding operations in baseactivity without writing more code.

Source address > >

summary

The above is the monitoring screenshot and QR code function code in android app introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>