Android应用程序与屏幕锁定工作 [英] Android application working with locked screen

查看:92
本文介绍了Android应用程序与屏幕锁定工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有一个应用程序,计算有多少时间拍照键为pressed。锁定的应用程序无法正常工作的屏幕后,那么有没有什么办法可以让计算presses当屏幕被锁定?

For example I have an app that counts how many time Camera button was pressed. After locking the screen the app is not working, so is there any way to keep counting presses when screen is locked?

推荐答案

运行的应用程序和服务都暂停,当手机被锁定,但你可以掌握WAKE_LOCK关键,做你的任务

Running Apps and services are pause when the phone is locked, but you can acquire WAKE_LOCK key and do your task

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyWakeLock"); 
wakeLock.acquire();

这将持有的CPU开,即使屏幕关闭

this will hold the CPU open even if the screen off

这篇关于Android应用程序与屏幕锁定工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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