Blog Infos
Author
Published
Topics
,
Author
Published

 

Android 14 introduces a privacy-preserving screenshot detection API to create a more standardized screenshot detection experience.

Apps can register callbacks on a per-activity basis using this API.

If the user takes a screenshot while that activity is visible, these callbacks are invoked, and the user is notified.

screenshot can only be detected if the user presses a specific combination of hardware buttons.

Implementation
Add permission to Manifest
  • This is an install-time permission, so we do not need to worry about it during runtime 🙌
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />

Implement ScreenCaptureCallback interface

  • A method called onScreenCaptured() needs to be overridden.
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
class MainActivity : ComponentActivity(), Activity.ScreenCaptureCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
             Text("Screenshot Detection API")    
        }
    }

    override fun onStart() {
        super.onStart()
        // Register callback to detect screenshot
        registerScreenCaptureCallback(mainExecutor, this)
    }

    override fun onStop() {
        super.onStop()
        // unregister callback to detect screenshot
        unregisterScreenCaptureCallback(this)
    }

    override fun onScreenCaptured() {
        // Inform the user or do whatever you want
        Log.d(TAG, "onScreenCaptured: Screenshot detected")
    }

    companion object {
        const val TAG = "MainActivity"
    }

    
}
Sample Code

Job Offers

Job Offers


    Senior Android Developer

    SumUp
    Berlin
    • Full Time
    apply now

    Senior Android Engineer

    Carly Solutions GmbH
    Munich
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

, ,

Safe Network API Migration Tactics

This talk is about how we at Uber migrated a critical endpoint from API to gRPC stack. This talk offers a roadmap through the complexities of updating your API infrastructure.
Watch Video

Safe Network API Migration Tactics

Chris Francis & Ashok Varma
Staff Software Engineer
Uber

Safe Network API Migration Tactics

Chris Francis & As ...
Staff Software Engin ...
Uber

Safe Network API Migration Tactics

Chris Francis & ...
Staff Software Engineer
Uber

Jobs

Demo
  • As I do not have an Android 14 device, the following screenshot comes from the official documentation.

 

https://developer.android.com/static/about/versions/14/images/screenshot-detection.svg

 

This article was previously published on proandroiddev.com

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
This tutorial is the second part of the series. It’ll be focussed on developing…
READ MORE
blog
We recently faced a problem with our application getting updated and reaching slowly to…
READ MORE
blog
A few weeks ago I started with a simple question — how to work…
READ MORE
blog
One of the main functions of a mobile phone was to store contacts information.…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu