android屏幕常亮

在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();
    }

 

你可能感兴趣的:(android)