-
-
Save iyotetsuya/08fcd889ebbf18dc95fef9110b805dfe to your computer and use it in GitHub Desktop.
Android 14 API Sample: Activity.ScreenCaptureCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.iyotetsuya.android14playgrounds | |
import android.app.Activity | |
import android.os.Bundle | |
import android.widget.Toast | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.annotation.RequiresApi | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.material.Text | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.unit.dp | |
import com.iyotetsuya.android14playgrounds.ui.theme.Android14PlaygroundsTheme | |
@RequiresApi(34) | |
class DetectScreenshotsActivity : ComponentActivity(), Activity.ScreenCaptureCallback { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
Android14PlaygroundsTheme { | |
Box(Modifier.fillMaxSize()) { | |
Text( | |
modifier = Modifier | |
.padding(4.dp) | |
.align(Alignment.Center), | |
text = "Detect Screenshots Activity" | |
) | |
} | |
} | |
} | |
} | |
override fun onStart() { | |
super.onStart() | |
registerScreenCaptureCallback(mainExecutor, this) | |
} | |
override fun onStop() { | |
super.onStop() | |
unregisterScreenCaptureCallback(this) | |
} | |
override fun onScreenCaptured() { | |
Toast.makeText( | |
this, "Screen Captured.", Toast.LENGTH_SHORT | |
).show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment