android PowerManager亮灭屏(实现篇)

编程入门 行业动态 更新时间:2024-10-08 02:23:35

<a href=https://www.elefans.com/category/jswz/34/1771384.html style=android PowerManager亮灭屏(实现篇)"/>

android PowerManager亮灭屏(实现篇)


网上查了好多资料 不是讲原理就是讲原理呀! 你Tm到是实现呀!!!墨迹一大篇文章,都是看的官文档然后加上自己的理解一顿墨迹。


具体讲下我要实现的功能:

Android 6.0实现自动亮灭屏幕,按下电源键屏幕灭屏5s后自动亮屏,时间可以自己设置

用到的知识有 1:powermanger的基础知识  

 2:超级管理员权限  重中之重呀!!!!

参考超级管理员链接点击打开链接

 3:Handler的基础知识

 4:BroadcastReceiver的广播通知的基础知识 

 5:基础知识相信大家找网上一大堆

 6:基础链接我就不给大家发了  相信你们比我找的好

 据说4.0以后为了安全,谷歌兄做了很多安全设施。power电池管理就很难搞了,整了一周费劲巴力的弄了出来

 

废话不多说了直接上代码。 放心代码一定要全部。

首先是MainActivity 的代码

package com.example.unruly_zhao.powermanager_wakelock;import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener {private Button startBtn = null;private Button stopBtn = null;private EditText timeEditText = null;private EditText delayEditText = null;private TextView textviewResult = null;private TextView textviewVersion = null;/*** 设备管理*/public DevicePolicyManager mDPM;/*** 次数*/int time;/*** 延迟时间*/int delay;/*** 计数*/int timeCount;/*** 中间数*/int timemid;/*** 组件*/ComponentName devAdmReceiver;protected String tag = getClass().getSimpleName();protected static final int REQUEST_ENABLE = 0;protected static final int GUI_DOING = 0;protected static final int GUI_FINISH = 1;private KeyguardManager km;private KeyguardLock kl;private PowerManager pm;private PowerManager.WakeLock wl;LockScreen lockScreen = new LockScreen();int sucCount;int failCount;String versionName = "2016_10_14_WakeUp_1.0";/*** handler  deal with msg*/Handler handler = new Handler() {public void handleMessage(android.os.Message msg) {switch (msg.what) {case GUI_DOING:Log.e(tag, "doing-->执行");String string = (String) msg.obj;textviewResult.setText(string);textviewResult.setGravity(Gravity.CENTER);break;case GUI_FINISH:Log.e(tag, "doing-->完成");String string1 = (String) msg.obj;textviewResult.setText(string1);textviewResult.setGravity(Gravity.CENTER);break;default:break;}};};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final IntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_SCREEN_OFF);fi

更多推荐

android PowerManager亮灭屏(实现篇)

本文发布于:2024-02-19 15:58:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:android   PowerManager   亮灭屏

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!