Activity of android above default lock screen using unity c# scripts

浪尽此生 提交于 2019-12-13 01:06:56

问题


how i can add WindowManager's LayoutParams flag inside unity c# scripts.

For example i can do it in Android by code as follow.

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:


you can do that like this:

AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaObject win = activity.Call<AndroidJavaObject>("getWindow"); AndroidJavaObject lp = new AndroidJavaClass("android/view/WindowManager$LayoutParams"); win.Call("addFlags",lp.GetStatic<int>("FLAG_SHOW_WHEN_LOCKED")); win.Call("addFlags",lp.GetStatic<int>("FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"));

i recently doing the same thing,it's work,it float on top of the lock screen,And if the user press HOME key,he will back to the system lock screen.

note that both "/" or "." is just the same. the $ is for inner class,in this case,LayoutParams is the inner class of WindowManager.



来源:https://stackoverflow.com/questions/26901440/activity-of-android-above-default-lock-screen-using-unity-c-sharp-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!