zoukankan      html  css  js  c++  java
  • Android保持背光常亮的设置方法

    1.
        为窗口添加flag:
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,

        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
       

        或者
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

     

    2.

       设置Layout中View的keepScreenOn属性: android:keepScreenOn="true"
      必须是可显示view才会起作用。

     

    3.

       使用电源管理:

       

    public class WakeLockActivity extends Activity { 
       
        PowerManager powerManager = null; 
        WakeLock wakeLock = null; 
       
        @Override 
        protected void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            this.setContentView(R.layout.main); 
            this.powerManager = (PowerManager) this 
                    .getSystemService(Context.POWER_SERVICE); 
            this.wakeLock = this.powerManager.newWakeLock( 
                    PowerManager.FULL_WAKE_LOCK, "My Lock"); 
        } 
       
        @Override 
        protected void onResume() { 
            super.onResume(); 
            this.wakeLock.acquire(); 
        } 
       
        @Override 
        protected void onPause() { 
            super.onPause(); 
            this.wakeLock.release(); 
        } 
       
    }

    添加权限:

    <uses-permission android:name="android.permission.WAKE_LOCK">
    </uses-permission>
  • 相关阅读:
    Java 多线程概述
    Java 线程的创建和启动
    状态模式
    Spring 依赖注入
    Spring IOC
    在JavaEE中使用Mybatis框架
    Active Reports 补空白行
    SpreadForWin 清空Sheet
    日期格式转换
    Select Case 的实现
  • 原文地址:https://www.cnblogs.com/lufengdie/p/2482681.html
Copyright © 2011-2022 走看看