相关文章推荐
无邪的橡皮擦  ·  拍照怎么连拍-掘金·  1 年前    · 
淡定的橙子  ·  Access ...·  1 年前    · 
In AndroidManifest.xml 加上权限:<uses-permission android:name="android.permission.WAKE_LOCK" /> public class UnLockActivity2 extends Activity { /** Called when the activity is first creat

In AndroidManifest.xml 加上权限:

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

public class UnLockActivity2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

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


public class UnLockActivity extends Activity {
/** Called when the activity is first created. */

WakeLock m_wklk;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
m_wklk = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cn");

m_wklk.acquire(); //设置保持唤醒
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
m_wklk.release(); //解除保持唤醒
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();

m_wklk.release();//解除保持唤醒

}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();


m_wklk.acquire(); //设置保持唤醒
}


}

PowerManager

主要是这两个参数: PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE

下面是 android 官方API 解释:

he following flags are defined, with varying effects on system power. These flags are mutually exclusive - you may only specify one of them.

Flag Value Screen Keyboard PARTIAL_WAKE_LOCK SCREEN_DIM_WAKE_LOCK SCREEN_BRIGHT_WAKE_LOCK Bright FULL_WAKE_LOCK Bright Bright

一般要使程序运行过程中背景保持常亮,使用

SCREEN_BRIGHT_WAKE_LOCK 就可以,

SCREEN_BRIGHT_WAKE_LOCK CPU:唤醒 屏幕背光:唤醒 键盘灯:关闭

第二个参数:

In addition, you can add two more flags, which affect behavior of the screen only. These flags have no effect when combined with a PARTIAL_WAKE_LOCK .

Flag Value Description ACQUIRE_CAUSES_WAKEUP Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately. ON_AFTER_RELEASE If this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions.

http://www.cnblogs.com/chengning/archive/2012/04/26/2472789.html

http://mysuperbaby.iteye.com/blog/1454178

http://wenku.baidu.com/view/a9c0fa01de80d4d8d15a4f96.html

http://blog.csdn.net/xieying15170814609/article/details/7723928

一文读懂系列Android屏幕刷新机制
对一些大中型项目来说可能就不一样了:**他们涉及业务较多,设备种类较多,往往一个app内部集成了十几个子业务甚至上百个,这对应用性能要求就更加严格了,app的体验也会间接导致用户的留存问题**。 所以学习屏幕绘制这类理论性较强的知识也是非常有必要的。
airserver安卓版手机屏幕投屏电脑神器
AirServer一款投屏神器,可以帮你轻松地将iPhone、iPad投屏到Mac。是不是经常看到游戏主播用AirServer投屏?此外,AirServer也是视频Up主必备工具之一!用来录制演示教程不错。除了实现单个手机投屏到电脑或荧幕。如果你有多画面投屏或者跨设备投屏的需求,不妨试试这个软件。