码迷,mamicode.com
首页 > 移动开发 > 详细

安卓屏幕常亮不锁屏

时间:2015-10-21 19:14:38      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 

private static AppActivity app = null;
    
@Override
    public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
        // TestCpp should create stencil buffer
        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
        
        app = this;
        return glSurfaceView;

    }

 

public static void setIdleTimer(final boolean idleFlag) {  
         Log.i(TAG, "setIdleTimer:" + idleFlag);
       //这里一定要使用runOnUiThread
         app.runOnUiThread(new Runnable() {
             @Override
             public void run() {
                 if (idleFlag) {
                     Log.i(TAG, "setIdleTimer1:" + idleFlag);
                     //wakeLock.acquire();
                     app.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                     Log.i(TAG, "setIdleTimer11:" + idleFlag);
                 }
                 else {
                     Log.i(TAG, "setIdleTimer2:" + idleFlag);
                     app.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                     Log.i(TAG, "setIdleTimer22:" + idleFlag);
                     //wakeLock.release(); 
                 }
             }
         });
     }   

 

安卓屏幕常亮不锁屏

标签:

原文地址:http://www.cnblogs.com/pengyingh/p/4898474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!