Android保持螢幕常亮

2021-06-23 09:32:19 字數 717 閱讀 3747

方法一:

// 新增許可權

// powermanager pm = (powermanager) getsystemservice(context.power_service);

powermanager.wakelock mwakelock = pm.newwakelock(

powermanager.screen_dim_wake_lock, "my tag");

// partial_wake_lock :保持cpu運轉,螢幕和鍵盤燈有可能是關閉的

// screen_dim_wake_lock :保持cpu運轉,允許保持螢幕顯示但有可能是灰的,允許關閉鍵盤燈

// screen_bright_wake_lock :保持cpu運轉,允許保持螢幕高亮顯示,允許關閉鍵盤燈

// full_wake_lock :保持cpu運轉,保持螢幕高亮顯示

mwakelock.acquire();// 獲得喚醒鎖

// mwakelock.release();// 解除喚醒鎖

方法二:

@override

protected void oncreate(bundle inicle) {

super.oncreate(inicle);

// 保持螢幕常亮

getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on);

Android 保持螢幕常亮

在activity的oncreate bundle 中新增以下 getwindow addflags windowmanager.layoutparams.flag keep screen on clearflags int 方法用來關閉 getwindow clearflags windowman...

Android 如何保持螢幕常亮

for example public class mainactivity extends activity 這個方法的好處是,與wakelocks不同 我們將在keep the cpu on文章中 它不需要具體的許可權,並且在換不同應用程式的操作中,系統會管理,不必擔心沒有釋放的未使用的資源。另一...

保持螢幕常亮

保持螢幕常亮方式一 public class textactivity extends activity sdk文件關於flag keep screen on的解釋如下 flag keep screen on added in api level 1 int flag keep screen on ...