Android disables System sleep so that the screen is not dimmed

Source: Internet
Author: User
Tags sleep function

Android disables System sleep, keeps the screen hidden, and keeps the screen highlighted in the game.

There are two ways to implement this function. One is to declare in the manifest. xml file, and the other isCodeModify the flag of layoutparams. The details are as follows:

1. Use user-Permission declaration in the manifest. xml file. The Code is as follows:

In this way, when installing the APK, the system will prompt the installer whether to allow the disable sleep function.

2.ProgramUse code. The Code is as follows:

    • Getwindow (). setflags (windowmanager. layoutparams. flag_keep_screen_on, windowmanager. layoutparams. flag_keep_screen_on );

Add this code before setcontentview (R. layout. Main ).
In this way, the installer is not prompted to disable sleep.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.