使用xamarin在默认锁屏上进行Android活动

时间:2014-11-10 06:40:33

标签: c# android xamarin lockscreen

我想知道我是如何在 xamarin 的C#代码中添加WindowManager LayoutParams标记的。

例如,我们可以通过以下代码在 Android 中执行此操作。

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

1 个答案:

答案 0 :(得分:8)

像这样:

namespace SampleCode
{
    [Activity (Label = "SampleCode", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            Window.AddFlags(WindowManagerFlags.KeepScreenOn|
                WindowManagerFlags.DismissKeyguard|
                WindowManagerFlags.ShowWhenLocked|
                WindowManagerFlags.TurnScreenOn);       
        }
    }
}