• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Android] Screenshot detection while user using your app

Android Arsenal Maven Central Minimum SDK Version Workflow Status

Android-ScreenshotDetection

Screenshot Detection Library

Download

Since version 1.0.1 will move from JCenter to MavenCentral

// build.gradle (project)
allprojects {
    repositories {
        mavenCentral()
        /* ... */
    }
}

Gradle

implementation 'com.akexorcist:screenshot-detection:1.0.2'

Permission in this library

This 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.

Usage

Implement the library to your activity or your base activity.

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

import com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate

open class ScreenshotDetectionActivity : AppCompatActivity(), ScreenshotDetectionDelegate.ScreenshotDetectionListener {
    private val screenshotDetectionDelegate = ScreenshotDetectionDelegate(this, this)

    override fun onStart() {
        super.onStart()
        screenshotDetectionDelegate.startScreenshotDetection()
    }

    override fun onStop() {
        super.onStop()
        screenshotDetectionDelegate.stopScreenshotDetection()
    }

    override fun onScreenCaptured(path: String) {
        // Do something when screen was captured
    }

    override fun onScreenCapturedWithDeniedPermission() {
        // Do something when screen was captured but read external storage permission has denied
    }
}

But 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.

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

open class ScreenshotDetectionActivity : AppCompatActivity(), ScreenshotDetectionDelegate.ScreenshotDetectionListener {
    /* ... */

    companion object {
        private const val REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION = 3009
    }

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

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        when (requestCode) {
            REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION -> {
                if (grantResults.getOrNull(0) == PackageManager.PERMISSION_DENIED) {
                    showReadExternalStoragePermissionDeniedMessage()
                }
            }
            else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        }
    }

    private fun checkReadExternalStoragePermission() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            requestReadExternalStoragePermission()
        }
    }

    private fun requestReadExternalStoragePermission() {
        ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSION)
    }

    private fun showReadExternalStoragePermissionDeniedMessage() {
        Toast.makeText(this, "Read external storage permission has denied", Toast.LENGTH_SHORT).show()
    }
}

Then extends your target activity with that base activity class and declare onScreenCaptured(path: String) and onScreenCapturedWithDeniedPermission() when you want to detect the screenshot.

import android.os.Bundle
import android.widget.Toast

class MainActivity : ScreenshotDetectionActivity() {
	/* ... */

    override fun onScreenCaptured(path: String) {
        Toast.make(this, path, Toast.LENGTH_SHORT).show();
        // Do something when screen was captured
    }

    override fun onScreenCapturedWithDeniedPermission() {
        Toast.make(this, "Please grant read external storage permission for screenshot detection", Toast.LENGTH_SHORT).show()
        // Do something when screen was captured but read external storage permission has denied
    }
}

Demo

Demo

Licence

Copyright 2021 Akexorcist

Licensed 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:

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

More Repositories

1

RoundCornerProgressBar

[Android] Round Corner Progress Bar Library for Android
Kotlin
2,496
star
2

BluetoothSPPLibrary

[UNMAINTAINED][Android] Bluetooth Serial Port Profile which comfortable to developer application to communication with microcontroller via bluetooth
Java
1,696
star
3

Localization

[Android] In-app language changing library
Kotlin
982
star
4

GoogleDirectionLibrary

[Android] Library for Google Direction API for Google Maps Android API v2
Java
572
star
5

ruam-mij-android

[Android] Display useful information about your device privacy
Kotlin
196
star
6

SnapTimePicker

[Android] Another Material Time Picker
Kotlin
127
star
7

GoogleDirectionAndPlaceLibrary

[Android] Library for Google Direction API and Google Place API for Google Maps Android API v2
Java
117
star
8

IOIO-CameraRobot

[Android] IOIO Robot Car with Real-time Camera from Android Device that Controlled with Another Android Device via WiFi
Java
75
star
9

Droid2JoyStick

[Android] Using android device as a gamepad to your PC or another android device.
Java
57
star
10

ConcatAdapterMultipleLayoutManager

[Android] Using ConcatAdapter with multiple LayoutManager in single RecyclerView
Kotlin
40
star
11

day-and-night-switch

Day & Night switch library for Compose Multiplatform
Kotlin
33
star
12

Glassmorphism

[Android] Glassmorphism UI experiment project
Kotlin
28
star
13

DeviceInformation

[Android] Collect android information for developer
Java
22
star
14

FileWriterCompat

[Android] File writing helper library for API Level 21+
Kotlin
19
star
15

ScreenOrientationHelper

[Android] Screen orientation event listener helper for activity in Android
Java
17
star
16

kotlin-multiplatform-presentation

Kotlin Multiplatform presentation that built with Kotlin Multiplatform and Compose Multiplatform
Kotlin
16
star
17

photo-on-cover-for-galaxy-z-flip5

[Android] Put your favorite photo on your cover screen and give your phone a personal touch.
Kotlin
15
star
18

workstation-diagram

[Kotlin Multiplatform] My workstation's interactive diagram
Kotlin
15
star
19

SimpleTCPLibrary

[UNMAINTAINED][Android] TCP Library for android to communicate with other android device or any embedded board via TCP protocol
Java
13
star
20

backdrop

Video and audio projection app for your streaming content on macOS
Kotlin
12
star
21

CameraX-Sample

[Android] Example of CameraX in Android Jetpack Library
Kotlin
12
star
22

Android-Sensor-Light

[Android] Using light sensor in Android devices
Java
11
star
23

ScreenChecker

[Android] Screen Checker application for development information
Kotlin
10
star
24

INEX-RFIDReader

Communicate with Serial RFID reader via USB Host on Android
Java
10
star
25

RecyclerView-DashLine

[Android] How to implement the RecyclerView with dash line between item
Kotlin
10
star
26

Android-CameraAutoFocus

Java
9
star
27

GroupFocusable

Android Custom View for prevent the view behind on-screen keyboard when edit text is focused
Kotlin
9
star
28

KnoxActivator

[Android] Samsung Knox Standard activation helper library for Android
Java
8
star
29

Example-SamsungSDK

[Android] Example of Samsung SDK and KNOX SDK in Android
Java
7
star
30

Android-DeviceInformation

[Android] Device information for developer
Java
7
star
31

RecyclerView-ListAdapter

[Android] ListAdapter in RecyclerView
Kotlin
7
star
32

CameraSample

[Android] Example of Camera API v1 and v2 implementation
Kotlin
7
star
33

HandleStateChangesInCustomView

[Android] Handle state changes in custom view and inherited custom view
Kotlin
7
star
34

Android-Sensor-Gyroscope

[Android] Using gyroscope in Android devices
Java
7
star
35

ImageResize

Effective image resizing in Android with BitmapFactory - Benchmark included
Kotlin
6
star
36

ArchitectureComponents-Repository

[Android] Repository in Android Architecture Components
Java
6
star
37

DialogExperiment

[Android] Best practice for Dialog creation in Android
Java
6
star
38

Android-AutoHideMenu

Auto Hide Menu Bar like as Google+ and Facebook
Java
6
star
39

Android-BluetoothSPP

Bluetooth Serial Port Profile library
Java
5
star
40

InstantDialog

[Android] Because I'm so boring about the Android dialog's boilerplate code
Kotlin
5
star
41

RootCheckerForSamsung

[Android] Root checking and running on Samsung devices
Java
5
star
42

coordinator-layout-catalogue

[Android] Example of coordinator layout implementation in different condition
Kotlin
5
star
43

SleepingForLess

[Android] Sleeping For Less Reader for Android
5
star
44

AndroidOreo-Features

[Android] Android 8.0 Oreo Features
Java
5
star
45

Android-SplashScreen

Real splash screen for application
Java
4
star
46

Dagger2-Sample

[Android] Dagger 2 in Android Project with AAC
Kotlin
4
star
47

ComplexRecyclerView

[Android] How I solve the problem when we have to handle very complex recycler view in Android
Kotlin
4
star
48

LovelyRecyclerView

[Android] RecyclerView with complex layout and data
Java
4
star
49

NewMvvmAac

[Android] New MVVM pattern with AAC that crystallize from iosched
Kotlin
3
star
50

Android-Sensor-Accelerometer

[Android] Using accelerometer in Android devices
Java
3
star
51

FirebaseAndroidCodelabs

[Android] Firebase project showcase in I/O Extended Thailand 2016
Java
3
star
52

RecyclerBackgroundSupportView

[Android] Add Image View behind RecyclerView with scrollable support
Kotlin
3
star
53

deep-link-generator

[React] Feel hard to test the deep link in your app? Yes, me too!
JavaScript
3
star
54

ProgressNotification

[Android] Example of progress notification when do some asynchronous things
Kotlin
3
star
55

DialogInteractor

[Android] Dialog helper which lifecycle awareness supports (powered by LiveData)
Kotlin
3
star
56

Android-ArchComponents

[Android] Example of Android Architecture Components
Java
2
star
57

BookApp

[Android] Sample application for communication with web service
Kotlin
2
star
58

Android-TextToSpeechThai

Example for Text to Speech with Thai language
Java
2
star
59

Android-BluetoothChat

Java
2
star
60

Android-GoogleAdMob

Using admob with google play service on android
Java
2
star
61

IOIO-Camera360

[Android] Change your IOIO board to 360 degree rotation photo capture - http://www.youtube.com/watch?v=js_ZpQCx-o8
Java
2
star
62

Shaky-FirebaseDevDay2018

[Android] Shaking game in Firebase Dev Day 2018 Bangkok
Kotlin
2
star
63

android-test-ui-hierarchy-to-json

[React] Make UI Hierarchy from Android testing more readable by parsing to JSON format
JavaScript
1
star
64

TextureViewVideoScaler

[Android] Very lightweight helper class to resize the video in texture view to fit center or crop center
Java
1
star
65

IOIO-TakeSnapshot

Java
1
star
66

sleepingforless-article-indexing-blogger

[NodeJS] Indexing the articles in Sleeping For Less by Blogger - https://www.akexorcist.com
JavaScript
1
star
67

android-ui-test-scroll-to-issue

Kotlin
1
star
68

ios-hardware-keyboard-issue-sample

Kotlin Multiplatform + Compose Multiplatform project for reproduce an issue on iOS
Kotlin
1
star
69

WiFlyTCP

[Arduino] Simple TCP Communication Library for WiFly RN-XV
Arduino
1
star
70

MotoXLED

[Android] Enable a hidden LED on Moto X - Rooted required
Java
1
star
71

Android-AnimationSimple

Java
1
star
72

NextzyMVP

[Android] MVP Project Structure that I use in my company project
Java
1
star
73

Android-Assist

Assist action on Android
Java
1
star
74

CodeBattle-Android

[Android] "Code Battle" for android in Firebase Dev Day
1
star
75

IOIO-Bot

Java
1
star
76

Android-ScreenshotDialog

Screenshot app screen with Dialog layout
Java
1
star
77

Simple-MVP

[Android] Simple code for MVP pattern
Java
1
star
78

DevDeviceInfo

[Android] Developer Device Information
Java
1
star
79

Example-NestedViewPager

Java
1
star
80

Example-CloudVision

Using Cloud Vision API in Android
Java
1
star
81

RecyclerView-ItemTouchHelper

[Android] ItemTouchHelper in RecyclerView
Kotlin
1
star
82

SimpleCustomView-Basic

[Android] Custom view with all required code
Java
1
star
83

Android-CustomListView

Java
1
star
84

FlexyStepIndicator

[Android] Step Indicator view with flexibility customization
Java
1
star
85

IOIO-LCDController

Java
1
star
86

EvenOdd

[Android] Example android app for Android CI with GitHub Actions and Firebase Test Lab
Kotlin
1
star
87

photo-picker-challenge

If someone tells you that your job as a programmer or Android Dev will be replaced by Generative AI in the future, give them this challenge to do. This will make your job safe.
Kotlin
1
star
88

RecyclerVIew-With-Loading-Task

The answer for some guy's question on android dev facebook group at https://goo.gl/kLNlnC
Java
1
star
89

SlidingPaneLayout-Sample

[Android] Example of AndroidX SlidingPaneLayout implementation
Kotlin
1
star
90

CurveSeekBar

[React] Custom your own curve seek bar in React - https://blog.nextzy.me/custom-curve-seek-bar-in-react-e1f213e87f8a
JavaScript
1
star
91

AkexorcistProfile

[Android] Example of On Demand Modules in Dynamic Delivery
Kotlin
1
star