锁屏时如何显示Activity?

发布于 2024-09-24 13:44:28 字数 62 浏览 1 评论 0原文

我的应用程序在汽车对接事件中启动,我想在插入设备时唤醒手机(由系统完成)并解锁屏幕。

有可能吗?

My application is launched on car docking event, I want to wake up phone (done by system) and unlock screen when I plug my device.

Is it posssible ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倥絔 2024-10-01 13:44:28

我用于将活动提升到最高水平

    private Window wind;
    @Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    /******block is needed to raise the application if the lock is*********/
    wind = this.getWindow();
    wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
    /* ^^^^^^^block is needed to raise the application if the lock is*/
}

I'm use for upping activity to top level

    private Window wind;
    @Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    /******block is needed to raise the application if the lock is*********/
    wind = this.getWindow();
    wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
    /* ^^^^^^^block is needed to raise the application if the lock is*/
}
神爱温柔 2024-10-01 13:44:28

使用 Activity.getWindow() 获取 Activity 的窗口;使用 Window.addFlags() 在 WindowManager.LayoutParams 中添加您想要的以下标志: FLAG_DISMISS_KEYGUARDFLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON

这就是标准车载底座的方式(和桌面底座)应用程序实现了此行为。

Use Activity.getWindow() to get the window of your activity; use Window.addFlags() to add whichever of the following flags in WindowManager.LayoutParams that you desire: FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON

This is how the standard car dock (and desk dock) app implements this behavior.

请爱~陌生人 2024-10-01 13:44:28

您只能将FLAG_DISMISS_KEYGUARD用于没有启用安全功能的锁(例如图案锁)的手机。

FLAG_SHOW_WHEN_LOCKED 只会将您当前的 Activity 置于顶部,如果用户尝试移动到其他地方,他将必须解锁屏幕。

或者,您可以在清单中添加权限:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

并且在创建活动中添加权限:

KeyguardManager manager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock lock = manager.newKeyguardLock("abc");
lock.disableKeyguard(); 

You will be able to use FLAG_DISMISS_KEYGUARD only for phones which do not have security enabled locks like pattern lock.

FLAG_SHOW_WHEN_LOCKED will only bring your current Activity on the top, if user tries to move elsewhere, he will have to unlock the screen.

Alternatively, you can add permission in your manifest:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

And, in your activity on create:

KeyguardManager manager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock lock = manager.newKeyguardLock("abc");
lock.disableKeyguard(); 
维持三分热 2024-10-01 13:44:28

当使用锁定图案或密码输入时,我还需要添加以下内容,因为屏幕会在不到 5 秒的时间内关闭:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

When using a lock pattern or a pin entry I needed to add the following as well because the screen turned off in less than 5 seconds:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文