-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathDetectorModule.kt
More file actions
40 lines (33 loc) · 1.39 KB
/
DetectorModule.kt
File metadata and controls
40 lines (33 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.reactnativedetector
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.modules.core.DeviceEventManagerModule
import android.app.Activity
class DetectorModule(val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ScreenshotDetectionListener {
private var screenshotDetectionDelegate: ScreenshotDetectionDelegate? = null
override fun getName(): String {
return "Detector"
}
@ReactMethod
fun startScreenshotDetection() {
val currentActivity = reactContext.currentActivity
if (currentActivity != null) {
screenshotDetectionDelegate = ScreenshotDetectionDelegate(currentActivity, this)
screenshotDetectionDelegate?.startScreenshotDetection()
}
}
@ReactMethod
fun stopScreenshotDetection() {
screenshotDetectionDelegate?.stopScreenshotDetection()
screenshotDetectionDelegate = null;
}
override fun onScreenCaptured(path: String) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("UIApplicationUserDidTakeScreenshotNotification", null)
}
override fun onScreenCapturedWithDeniedPermission() {
// Todo: send user notification.
}
}