Xamarin Android: Dismiss lock screen or show activity on lock screen
To gain an Activity to be showed on the lock screen, or bypass the phone’s lock screen (aka Keyguard) for important notification handling, for example an Incoming VOIP call, you need to do the following:
Set the permission for disabling keyguard. Add the following permission to the AndroidManifest.xml:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
Add flags to the Activity’s Window in order to show the activity on the lock screen, or to bypass the lock screen.
this.Window.AddFlags(WindowManagerFlags.DismissKeyguard | WindowManagerFlags.ShowWhenLocked);
Dismiss the keyguard if needed. (CrossCurrentActivity plugin is used to get the current activity):
KeyguardManager keyguardManager = (KeyguardManager)CrossCurrentActivity.Current.Activity?.GetSystemService(Context.KeyguardService);
if (keyguardManager != null)
{
keyguardManager.RequestDismissKeyguard(CrossCurrentActivity.Current.Activity, null);
}
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
![](https://www.banditoth.net/wp-content/uploads/2024/10/image.png)
Hi, I am András,
I am a seasoned software engineer from Budapest, Hungary with a strong focus on mobile app development using .NET MAUI and Xamarin.Forms. My expertise also extends to website building for my happy customers and other complex system designing. I am passionate about developing well-organized, maintainable software solutions.
![](https://www.banditoth.net/wp-content/uploads/2022/08/Screenshot-2022-08-29-at-23.49.40-1024x349.png)
![](https://www.banditoth.net/wp-content/uploads/2022/08/68747470733a2f2f7777772e706c616e657478616d6172696e2e636f6d2f436f6e74656e742f696d672f706c616e657478616d6172696e2d66656174757265642d62616467652e706e67.png)