Android Bright screen and quenching screen control example detailed _android

Source: Internet
Author: User

This article describes the Android screen and the implementation of the quenching screen control method. Share to everyone for your reference, specific as follows:

I. Overview

Many of our Android apps need to work with a splash screen and an off screen, like an alarm clock, which needs to be lit and then extinguished. So today, we're going to analyze the function in this area.

Two. System service Powermanager.java

As the name suggests, Powermanager.java is to manage the power of our functions, of course, including our screen light and off. Yes, our application uses this system service to achieve the function of both the screen and the quenching screen.

1. The application obtains the PowerManager service, we may write this:

Copy Code code as follows:
PowerManager pm = (powermanager) getsystemservice (Context.power_service);

Because PowerManager is a system service, its lifecycle is not controlled by the application; The application can only get the PowerManager service through the system, and then the system uses the service to us.

2. Gotosleep () method, this method can force our screen to extinguish. We can call this:
After you get the PM object, this calls

Pm.gotosleep (Systemclock.uptimemillis ());

3. Setbacklightbrightness () method, this method can set the brightness of the backlight, from 0-255

Three. Timed off screen

So here, you can also introduce a way to control the screen is Powermanager.wakelock
As the name suggests, Wakelock this thing is the bright screen control, here said the bright screen, it defines several types of light screen. As follows:

Type Cpu Screen Keyboard
Partial_wake_lock On Off Off
Screen_dim_wake_lock On Dim Off
Screen_bright_wake_lock On Bright Off
Full_wake_lock On Bright Bright

Because it defines so many types, each type can specify the corresponding parts to work and not work. Then we can take advantage of these types, from the most fine-grained to control our screen, control our power supply, so that our power supply working time as long as possible (we all know that the smartphone battery problem is a mishap, every day a charge, there is wood?) Other people say that the man who uses the Android phone is a good family man because he has to go home to recharge every night. ^^).

Okay, okay, no gossip, go on.

How do you use this wakelock? We can write this:

PowerManager pm = (powermanager) getsystemservice (context.power_service);
Powermanager.wakelock Wakelock = Pm.newwakelock (Powermanager.screen_dim_wake_lock, "TAG");
Wakelock.acquire ();
Do our work, at this stage, our screen will continue to light up
/release the lock, the screen goes off.
wl.release ();

So here we can also use that is how much time after the screen off
First light the screen.

PowerManager pm = (powermanager) getsystemservice (context.power_service);
Powermanager.wakelock Wakelock = Pm.newwakelock (Powermanager.screen_dim_wake_lock, "TAG");
Wakelock.acquire ();

And then

Mtimehandler.postdelayed (New Runnable () {public
    void run () {
      wakelock.release ();
    }
}, 10*1000);

Well, delay the 10s and turn off the screen ....

So, notice here that acquire () and release () are called pairs! In other words, you apply for the screen, and after a while you release it.

For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", "Android Basic Components Usage Summary", " Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

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.