{"id":21313842,"url":"https://github.com/akexorcist/screenshotdetection","last_synced_at":"2026-01-11T17:34:33.008Z","repository":{"id":41687809,"uuid":"107241081","full_name":"akexorcist/ScreenshotDetection","owner":"akexorcist","description":"[Android] Screenshot detection while user using your app","archived":false,"fork":false,"pushed_at":"2022-04-29T07:30:17.000Z","size":516,"stargazers_count":160,"open_issues_count":3,"forks_count":31,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-16T12:30:06.322Z","etag":null,"topics":["android","android-library","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akexorcist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-17T08:39:35.000Z","updated_at":"2024-04-05T02:57:31.000Z","dependencies_parsed_at":"2022-08-10T10:06:40.658Z","dependency_job_id":null,"html_url":"https://github.com/akexorcist/ScreenshotDetection","commit_stats":null,"previous_names":["akexorcist/android-screenshotdetection"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akexorcist%2FScreenshotDetection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akexorcist%2FScreenshotDetection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akexorcist%2FScreenshotDetection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akexorcist%2FScreenshotDetection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akexorcist","download_url":"https://codeload.github.com/akexorcist/ScreenshotDetection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225778862,"owners_count":17522710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","kotlin"],"created_at":"2024-11-21T18:08:57.250Z","updated_at":"2026-01-11T17:34:32.979Z","avatar_url":"https://github.com/akexorcist.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Screenshot%20Detection-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/8241)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.akexorcist/screenshot-detection/badge.svg)](https://search.maven.org/artifact/com.akexorcist/screenshot-detection) \n![Minimum SDK Version](https://img.shields.io/badge/minSdkVersion-16-brightgreen) \n[![Workflow Status](https://github.com/akexorcist/ScreenshotDetection/actions/workflows/android.yml/badge.svg)](https://github.com/akexorcist/ScreenshotDetection/actions)\n\n# Android-ScreenshotDetection\n\nScreenshot Detection Library\n\n# Download\n\nSince version 1.0.1 will [move from JCenter to MavenCentral](https://developer.android.com/studio/build/jcenter-migration)\n```groovy\n// build.gradle (project)\nallprojects {\n    repositories {\n        mavenCentral()\n        /* ... */\n    }\n}\n```\n\n**Gradle**\n```\nimplementation 'com.akexorcist:screenshot-detection:1.0.2'\n```\n\n# Permission in this library\n\nThis library has declared the permission to read the external storage. So you need to handle the runtime permission by yourself. If not, app will not crash and screenshot detection still work but no file path.\n\n# Usage\n\nImplement the library to your activity or your base activity.\n\n```kotlin\nimport android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\n\nimport com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate\n\nopen class ScreenshotDetectionActivity : AppCompatActivity(), ScreenshotDetectionDelegate.ScreenshotDetectionListener {\n    private val screenshotDetectionDelegate = ScreenshotDetectionDelegate(this, this)\n\n    override fun onStart() {\n        super.onStart()\n        screenshotDetectionDelegate.startScreenshotDetection()\n    }\n\n    override fun onStop() {\n        super.onStop()\n        screenshotDetectionDelegate.stopScreenshotDetection()\n    }\n\n    override fun onScreenCaptured(path: String) {\n        // Do something when screen was captured\n    }\n\n    override fun onScreenCapturedWithDeniedPermission() {\n        // Do something when screen was captured but read external storage permission has denied\n    }\n}\n```\n\nBut above example will not work because read the external storage permission has denied. To fix this, you need to add the code for runtime permission request.\n\n```kotlin\nimport android.Manifest\nimport android.content.pm.PackageManager\nimport android.os.Bundle\nimport android.widget.Toast\nimport androidx.appcompat.app.AppCompatActivity\nimport androidx.core.app.ActivityCompat\nimport androidx.core.content.ContextCompat\n\nopen class ScreenshotDetectionActivity : AppCompatActivity(), ScreenshotDetectionDelegate.ScreenshotDetectionListener {\n    /* ... */\n\n    companion object {\n        private const val REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION = 3009\n    }\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        checkReadExternalStoragePermission()\n    }\n\n    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array\u003cout String\u003e, grantResults: IntArray) {\n        when (requestCode) {\n            REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION -\u003e {\n                if (grantResults.getOrNull(0) == PackageManager.PERMISSION_DENIED) {\n                    showReadExternalStoragePermissionDeniedMessage()\n                }\n            }\n            else -\u003e super.onRequestPermissionsResult(requestCode, permissions, grantResults)\n        }\n    }\n\n    private fun checkReadExternalStoragePermission() {\n        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {\n            requestReadExternalStoragePermission()\n        }\n    }\n\n    private fun requestReadExternalStoragePermission() {\n        ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION)\n    }\n\n    private fun showReadExternalStoragePermissionDeniedMessage() {\n        Toast.makeText(this, \"Read external storage permission has denied\", Toast.LENGTH_SHORT).show()\n    }\n}\n```\n\nThen extends your target activity with that base activity class and declare `onScreenCaptured(path: String)` and `onScreenCapturedWithDeniedPermission()` when you want to detect the screenshot.\n\n```kotlin\nimport android.os.Bundle\nimport android.widget.Toast\n\nclass MainActivity : ScreenshotDetectionActivity() {\n\t/* ... */\n\n    override fun onScreenCaptured(path: String) {\n        Toast.make(this, path, Toast.LENGTH_SHORT).show();\n        // Do something when screen was captured\n    }\n\n    override fun onScreenCapturedWithDeniedPermission() {\n        Toast.make(this, \"Please grant read external storage permission for screenshot detection\", Toast.LENGTH_SHORT).show()\n        // Do something when screen was captured but read external storage permission has denied\n    }\n}\n```\n\n# Demo\n\n![Demo](https://raw.githubusercontent.com/akexorcist/Android-ScreenshotDetection/master/Images/screenshot_001.gif)\n\n# Licence\n\nCopyright 2021 Akexorcist\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakexorcist%2Fscreenshotdetection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakexorcist%2Fscreenshotdetection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakexorcist%2Fscreenshotdetection/lists"}