手机被锁定在android中时使用什么代替过时的FLAG_SHOW_WHEN_LOCKED标志来启动活动 [英] What to use instead of deprecated FLAG_SHOW_WHEN_LOCKED flag to start activity when phone is locked in android

查看:886
本文介绍了手机被锁定在android中时使用什么代替过时的FLAG_SHOW_WHEN_LOCKED标志来启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使手机已锁定,我也希望广播开始一项活动. 我发现的是,确实有窗口标记FLAG_SHOW_WHEN_LOCKED和FLAG_TURN_SCREEN_ON可以完全满足我的需要.问题在于它们在最新版本的android中已弃用.

I want broadcast to start an activity even when the phone is locked. What I have found is that there are window flags FLAG_SHOW_WHEN_LOCKED and FLAG_TURN_SCREEN_ON that do exactly what I need. The problem is that they are deprecated in the latest versions of android.

我还发现可以使用setShowWhenLocked(true)和setTurnScreenOn(true)方法,但是它们给我一个错误在Someclass类中没有虚拟方法setShowWhenLocked(Z)V"

Also I found out that setShowWhenLocked(true) and setTurnScreenOn(true) methods can be used but they give me an error "No virtual method setShowWhenLocked(Z)V in class Someclass"

您能建议我如何实现所需的结果吗?

Could you suggest how I could achieve the needed outcome?

推荐答案

使用activityObj.setShowWhenLocked (true)代替FLAG_SHOW_WHEN_LOCKED

使用setTurnScreenOn()代替FLAG_TURN_SCREEN_ON

注意:这些方法仅在API级别27中可用.因此,在使用它之前,您需要进行一些检查

Note: These methods are only available from API level 27. So you need to perform some checking prior to using it

if (Build.VERSION.SDK_INT >= 27) {
        setShowWhenLocked(true)
        setTurnScreenOn(true)
    } else {
        this.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
    }

这篇关于手机被锁定在android中时使用什么代替过时的FLAG_SHOW_WHEN_LOCKED标志来启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆