日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

android 屏幕保持唤醒 不锁屏 android.permission.WAKE_LOCK

發(fā)布時(shí)間:2024/9/27 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 屏幕保持唤醒 不锁屏 android.permission.WAKE_LOCK 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
 In AndroidManifest.xml 加上權(quán)限:

<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(); //設(shè)置保持喚醒
}

@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(); //設(shè)置保持喚醒
}


}

?

解釋:

用到的類

PowerManager

主要是這兩個(gè)參數(shù):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 ValueCPUScreenKeyboardPARTIAL_WAKE_LOCKSCREEN_DIM_WAKE_LOCKSCREEN_BRIGHT_WAKE_LOCKFULL_WAKE_LOCK
On*OffOff
OnDimOff
OnBrightOff
OnBrightBright

一般要使程序運(yùn)行過(guò)程中背景保持常亮,使用

SCREEN_BRIGHT_WAKE_LOCK 就可以,

SCREEN_BRIGHT_WAKE_LOCK?CPU:喚醒 屏幕背光:喚醒 鍵盤燈:關(guān)閉

第二個(gè)參數(shù):

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

Flag ValueDescriptionACQUIRE_CAUSES_WAKEUPON_AFTER_RELEASE
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.
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

總結(jié)

以上是生活随笔為你收集整理的android 屏幕保持唤醒 不锁屏 android.permission.WAKE_LOCK的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。