Android Lockscreen with FingerPrint support

纵然是瞬间 提交于 2019-12-06 03:25:45

I`ve finally solved it. The key is to not listen for fingerprint myself but just let system handle it. My lockscreen is view that is added to WindowManager like this

val params = WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION or
                            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
                            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
                            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
                            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
                            WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
                    , PixelFormat.TRANSLUCENT)

manager.addView(lockscreenView, params)

and lockscreen view in onViewAttached sets UI visibility flags

override fun onAttachedToWindow() {
    super.onAttachedToWindow()
    systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
 }

Then you have to provide your own custom unlock mechanism so user can dismiss your lockscreen and additionaly listen for Intent.ACTION_USER_PRESENT broadcast that indicates that lockscreen is unlocked (for example with fingerprint)

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