---
title: "android屏幕常亮"
author: "羊咩咩"
date: "2013-11-16T20:43:11Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2013-11-16T20:43:11Z"
id: 1975998
url: "https://dblog.iteye.com/blog/1975998"
---

在manifest.xml中配置权限：

```
<!--常亮权限  -->
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
```

 

在activity的java文件中：

```
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_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();
    }
```