Android 屏幕灭屏亮屏广播,屏幕灭屏亮屏监听,广播实现按键监听

service 类注册广播进行监听

/*** 作者:created by meixi* 邮箱:13164716840@163.com* 日期:2018/9/27 09*/
public class Serview extends Service {/*** 广播接受者*/private BroadcastReceiver mBatInfoReceiver;private String TAG = "lgq--------------------";@Overridepublic void onCreate() {super.onCreate();
//        Log.d(TAG, "onCreate()");
//        initNotification();
//        initTodayData();initBroadcastReceiver();
//        new Thread(new Runnable() {
//            public void run() {
//                startStepDetector();
//            }
//        }).start();
//        startTimeCount();}/*** 注册广播*/private void initBroadcastReceiver() {final IntentFilter filter = new IntentFilter();// 屏幕灭屏广播filter.addAction(Intent.ACTION_SCREEN_OFF);//关机广播filter.addAction(Intent.ACTION_SHUTDOWN);// 屏幕亮屏广播filter.addAction(Intent.ACTION_SCREEN_ON);// 屏幕解锁广播
//        filter.addAction(Intent.ACTION_USER_PRESENT);// 当长按电源键弹出“关机”对话或者锁屏时系统会发出这个广播// example:有时候会用到系统对话框,权限可能很高,会覆盖在锁屏界面或者“关机”对话框之上,// 所以监听这个广播,当收到时就隐藏自己的对话,如点击pad右下角部分弹出的对话框filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);//监听日期变化filter.addAction(Intent.ACTION_DATE_CHANGED);filter.addAction(Intent.ACTION_TIME_CHANGED);filter.addAction(Intent.ACTION_TIME_TICK);mBatInfoReceiver = new BroadcastReceiver() {@Overridepublic void onReceive(final Context context, final Intent intent) {String action = intent.getAction();if (Intent.ACTION_SCREEN_ON.equals(action)) {Log.i(TAG, "screen on");} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {Log.i(TAG, "screen off");//改为60秒一存储
//                    duration = 60000;} else if (Intent.ACTION_USER_PRESENT.equals(action)) {Log.i(TAG, "screen unlock");
//                    save();//改为30秒一存储
//                    duration = 30000;} else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {Log.i(TAG, " receive Intent.ACTION_CLOSE_SYSTEM_DIALOGS");//保存一次
//                    save();} else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {Log.i(TAG, " receive ACTION_SHUTDOWN");
//                    save();} else if (Intent.ACTION_DATE_CHANGED.equals(action)) {//日期变化步数重置为0
//                    Logger.d("重置步数" + StepDcretor.CURRENT_STEP);
//                    save();
//                    isNewDay();} else if (Intent.ACTION_TIME_CHANGED.equals(action)) {//时间变化步数重置为0Log.i("lgq000000000000","sssss时间变化步数重置为0===="+action);
//                    isCall();
//                    save();
//                    isNewDay();} else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期变化步数重置为0Log.i("lgq0000000000000000","日期变化步数重置为0===="+action);
//                    isCall();
//                    Logger.d("重置步数" + StepDcretor.CURRENT_STEP);
//                    save();
//                    isNewDay();}}};registerReceiver(mBatInfoReceiver, filter);}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}
}

<service android:name=".testt.Serview"><intent-filter><!-- 系统启动完成后会调用--><action android:name="android.intent.action.BOOT_COMPLETED" /><action android:name="android.intent.action.DATE_CHANGED" /><action android:name="android.intent.action.MEDIA_MOUNTED" /><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.intent.action.ACTION_TIME_TICK" /><action android:name="android.intent.action.ACTION_POWER_CONNECTED" /><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /></intent-filter>
</service>

    /*** 开启计步服务*/private void setupService() {Intent intent = new Intent(this, Serview.class);
//        isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);startService(intent);}

 

实现demo:安卓广播监听按键事件和屏幕熄屏亮屏监听-Android文档类资源-CSDN下载 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415136.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python WindroseAxes 报错 has no attribute ‘Appender‘

引用代码 from windrose import WindroseAxes报错&#xff1a;module matplotlib.docstring has no attribute Appender 问题是我目前安装的python 3.8&#xff0c;windrose也要安装最新的。 安装方法 第一种&#xff1a; pip install githttps://github.com/python-windr…

[转载] 我的WafBypass之道(SQL注入篇)

我的WafBypass之道&#xff08;SQL注入篇&#xff09; Web安全 作者&#xff1a;先知技术社区 2016-11-23 7,566【本文转自安全脉搏战略合作伙伴先知技术社区 原帖地址 安全脉搏编辑huan9740整理发布】 0x00 前言 去年到现在就一直有人希望我出一篇关于waf绕过的文章&#xf…

Android 设置系统闹钟,日历写入。实现demo

实现方法1——代码闹钟 可变时间格式&#xff1a;"yyyy-MM-dd HH:mm:ss" 保存闹钟时间&#xff1a; SimpleDateFormat df new SimpleDateFormat("HH:mm");//设置日期格式 String thistime df.format(new Date()); SharedPreferences sharedPreferenc…

centos 安装 fortran

1、 yum install gcc-c2、 yum install gcc-gfortran

前端学习(2677):懂代码之表格BaseTable删除操作

1第一步 <el-table-column label"操作" width"180" align"center"><template slot-scope"scope"><el-buttontype"text"icon"el-icon-edit"click"handleEdit(scope.$index, scope.row)"&…

Linux之Ubuntu下安装屏幕录像软件(SimpleScreenRecorder)【摘抄】

本博文全文属于摘抄自&#xff1a; (见文末处参考文献)(由于担心原博文丢失&#xff0c;以后查找不到&#xff0c;故此原文摘抄&#xff0c;以备日后多次查阅) 在日常工作中&#xff0c;有时需要对屏幕进行录像&#xff0c;以制作讲解文档等。下面介绍在Linux上安装屏幕录像软件…

Android精准计步器

demo链接&#xff1a;https://download.csdn.net/download/meixi_android/10690974 工具类&#xff1a; public class StepDetector implements SensorEventListener {//存放三轴数据float[] oriValues new float[3];final int ValueNum 4;//用于存放计算阈值的波峰波谷差值…

docker 目录 挂载

docker容器启动的时候&#xff0c;如果要挂载宿主机的一个目录&#xff0c;可以用-v参数指定。 譬如我要启动一个centos容器&#xff0c;宿主机的/share目录挂载到容器的/share目录&#xff0c;可通过以下方式指定&#xff1a; docker run -it -v /share:/share centos /bin/…

工作177:表单重置项目处理

<template><!--新建账号对话框--><el-dialog title"新建账号" :visible.sync"dialogFormVisible" close"close"><el-form ref"form" :model"form" size"medium" :label-width"formLabe…

docker删除所有镜像和容器

需求&#xff1a;重新进行开发&#xff0c;需要清空目前的镜像和容器。 1、删除容器 1&#xff09;首先需要停止所有的容器 docker stop $(docker ps -a -q) 2&#xff09;删除所有的容器&#xff08;只删除单个时把后面的变量改为image id即可&#xff09; docker rm $(d…

Ubuntu配置完全教程

前言 最近将旧电脑换成了Ubuntu系统&#xff0c;在网上找了许多优化和配置教程&#xff0c;今天整理一份完整的教程给大家分享 系统清理 卸载LibreOffice libreoffice事ubuntu自带的开源office软件&#xff0c;体验效果不如windows上的office&#xff0c;于是选择用WPS来替代&a…

Android assets文件使用

1、在main文件夹下创建assets文件夹 2、assets文件夹下可创建image文件夹&#xff0c;text文件夹&#xff0c;image文件夹下存放jpg或png图片。text文件夹下存放.txt文本 3、读取assets文件内容&#xff1a; entity类&#xff1a; public class Book {private static final…

工作176:表单重置

复制代码 <el-form :model"loginForm" ref"loginFormRef"> // 1. 需要给表单指定 ref 属性 , 可以理解为表单的 名字<!-- 用户名 --><el-form-item prop"username"> // 2. 需要给 需要重置 的表单项指定 prop 属性, 值…

《掌握需求过程》阅读笔记05

需求策略需要平衡需求知识、活动和人。沟通需求知识的一致的语言&#xff0c;发现和传播知识的活动&#xff0c;参与的人&#xff0c;这些是影响需求策略的所有变量。 需求策略是一个活动的框架&#xff0c;需要根据给定的项目轮廓&#xff0c;执行这些活动。在工作中常遇到的轮…

Android 自定义字体,设置字体

效果图 实现代码&#xff1a; 1、先下载字体文件.ttf 下载链接&#xff1a;http://font.chinaz.com/maobiziti.html 2、main文件夹下创建fonts文件夹&#xff0c;.ttf文件复制到fonts文件夹下 3、读取ttf文件 List<Typeface> mTypefaceList new ArrayList(); priva…

docker 安装 centos

1、设置docker 镜像加速 三个源 名称路径网易https://hub-mirror.c.163.com/阿里云https://<你的ID>.mirror.aliyuncs.com七牛云加速器https://reg-mirror.qiniu.com "registry-mirrors":["https://hub-mirror.c.163.com/","https://reg-mirr…

工作177:时间戳转换

main.js // 将时间戳转日期格式的过滤器 Vue.filter(dateFormat, (dataStr) > {var time new Date(dataStr);function timeAdd0(str) {if (str < 10) {str 0 str;}return str}var y time.getFullYear();var m time.getMonth() 1;var d time.getDate();var h time…

管理点收集

1.建立一个“建议组” 来允许员工说出对工作过程中的不合理的地方的建议&#xff0c;不断收集建议 定期整改2.站立会议的按时举行3.文档管理制定负责人4.代码管理 版本定期发布5.尽可能的让员工之间的工作减少相互依赖&#xff08;减少相互之间的等待&#xff09;6.“所有人应该…

Android 简单几行代码实现摇一摇功能

1、activity 实现加速度监听类 。。。。implements SensorEventListener public class MainActivity extends AppCompatActivity implements SensorEventListener { 2、activity实现两个方法&#xff1a; Overridepublic void onSensorChanged(SensorEvent sensorEvent) {Se…

docker centos 环境 安装 python

1、下载安装python编译环境依赖 yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel #安装make编译所需的gcc,g编译器 yum -y install gcc automake autoconf libtool make wget 2、移除centos中自带的python2.7的环境变量 cd /…