Android ScreenLockReceiver监听锁屏功能示例
程序员文章站
2022-03-24 18:17:03
本文实例讲述了android screenlockreceiver监听锁屏功能。分享给大家供大家参考,具体如下:
监听屏幕锁屏状态(注册接受者--执行业务--注销接受者)...
本文实例讲述了android screenlockreceiver监听锁屏功能。分享给大家供大家参考,具体如下:
监听屏幕锁屏状态(注册接受者--执行业务--注销接受者)
public class applockservice extends service { private activitymanager am; private keyguardmanager keyguardmanager; private lockscreenreceiver receiver; @override public void oncreate() { // todo auto-generated method stub super.oncreate(); am = (activitymanager) getsystemservice(context.activity_service); keyguardmanager = (keyguardmanager) getsystemservice(context.keyguard_service); //注册锁屏广播接收者 intentfilter filter = new intentfilter(); filter.addaction(intent.action_screen_off); receiver = new lockscreenreceiver(); registerreceiver(receiver, filter); new thread(){ public void run() { //一直在监听锁屏动作,一旦监听到,便执行操作 while(true){ boolean islockscreen = keyguardmanager.inkeyguardrestrictedinputmode(); /**此处可作相应操作*/ } }; }.start(); } private final class lockscreenreceiver extends broadcastreceiver{ @override public void onreceive(context context, intent intent) { tempapplocks.clear(); } } @override public void ondestroy() { super.ondestroy(); //取消锁屏的广播监听 unregisterreceiver(receiver); } }
更多关于android相关内容感兴趣的读者可查看本站专题:《android开发入门与进阶教程》、《android调试技巧与常见问题解决方法汇总》、《android基本组件用法总结》、《android视图view技巧总结》、《android布局layout技巧总结》及《android控件用法总结》
希望本文所述对大家android程序设计有所帮助。