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);
}

This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.