Android-让活动覆盖在一切之上

Android-让活动覆盖在一切之上,android,android-windowmanager,Android,Android Windowmanager,我要从我的服务启动一个活动,我想让它覆盖在一切之上,就像WindowManager一样,其他应用程序无法在上面显示 我在super.onCreate()之前的onCreate()中使用了此代码,但它不起作用 override fun onCreate(savedInstanceState: Bundle?) { setWindowFlags() super.onCreate(savedInstanceState) } 请帮帮我。提前谢谢 请帮帮我。 private fun se

我要从我的服务启动一个活动,我想让它覆盖在一切之上,就像WindowManager一样,其他应用程序无法在上面显示

我在
super.onCreate()
之前的
onCreate()
中使用了此代码,但它不起作用

override fun onCreate(savedInstanceState: Bundle?) {
    setWindowFlags()
    super.onCreate(savedInstanceState)
}

请帮帮我。提前谢谢

请帮帮我。
private fun setWindowFlags() {
    val type = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
    } else {
        WindowManager.LayoutParams.TYPE_PHONE
    }
    window?.setType(type)

    window?.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
    window?.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
    window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN)
    window?.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
    window?.addFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON)
}