Android保持屏幕唤醒状态(即背景灯不熄灭)

来源:互联网 发布:2016能看片的软件 编辑:程序博客网 时间:2024/04/30 18:42

转自:http://www.oschina.net/code/snippet_936286_23625

/**

     * 保持屏幕唤醒状态(即背景灯不熄灭)
     *
     * @param on
     *            是否唤醒
     */
    private static WakeLock wl;
    public static void keepScreenOn(Context context, boolean on) {
        if (on) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "==KeepScreenOn==");
            wl.acquire();
        } else {
            if (wl != null) {
                wl.release();
                wl = null;
            }
        }
    }
原创粉丝点击