I've set configs due to documentation. The lock screen is turned on in Api<34 and emulator API 34 but not in real device Android 34. Here's the code:
fun turnOnScreenLock(activity: AppCompatActivity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
activity.setShowWhenLocked(true)
activity.setTurnScreenOn(true)
val keyguardManager =
activity.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager?
keyguardManager?.requestDismissKeyguard(activity, null)
activity.window.addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON)
} else
activity.window.addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
Also here is the manifest:
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
...
<activity
android:name="de.netalic.messenger.ui.videocall.IncomingCallActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/MainActivityTheme"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:showOnLockScreen="true"
android:excludeFromRecents="true"/>