From 57804c8d6208da3ddb5d328ba720f1af39b00853 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 28 Oct 2021 16:26:03 +0200 Subject: [PATCH] dismiss keyguard for CallNotificationActivity (WIP, see TODO) Whenever i click the button to accept the call, CallActivity is started by intent. CallActivity itself has the same logic to dismiss the keyguard. The problem is: When switching from CallNotificationActivity to CallActivity the lockscreen is shown indeed! So i guess Android recognizes "oh, CallNotificationActivity is gone. Let's show the lockscreen" before it recognizes that the new activity also dismiss the lockscreen ?! I fear for this scenario it was not the best idea to have 2 different activies.. (before it was only 1 activity and 2 condcutor controllers..) Signed-off-by: Marcel Hibbe --- app/src/main/AndroidManifest.xml | 6 +++-- .../activities/CallNotificationActivity.java | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 28470ec9d..1d0260733 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -129,7 +129,8 @@ android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:launchMode="singleTask" android:taskAffinity=".call" - android:excludeFromRecents="true" /> + android:excludeFromRecents="true" + android:showOnLockScreen="true"/> + android:excludeFromRecents="true" + android:showOnLockScreen="true" /> = Build.VERSION_CODES.O) { enterPictureInPictureMode(getPipParams()); } else { @@ -526,4 +531,19 @@ public class CallNotificationActivity extends BaseActivity { binding.callAnswerButtons.setVisibility(View.VISIBLE); binding.incomingCallRelativeLayout.setVisibility(View.VISIBLE); } + + // TODO: dismiss keyguard works, but whenever accepting the call and switch to CallActivity by intent, the + // lockscreen is shown (although CallActivity also dismisses the keyguard in the same way.) + private void dismissKeyguard() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(true); + setTurnScreenOn(true); + KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); + keyguardManager.requestDismissKeyguard(this, null); + } else { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + } + } } \ No newline at end of file