android4.0+ Lock Screen Program development--Set the lock screen page

Source: Internet
Author: User

"How to develop a lock screen app"

To develop a lock screen application, it seems difficult, in fact, it is not as difficult as imagined.

In essence, the lock screen interface is only an activity, but this interface is very special, when we light the screen, the interface will appear.

And in this interface, we can use some behavior to exit, such as Click button and so on.

There is also a feature in this interface when we are usually unable to use the bottom of the three buttons

About if the three buttons at the bottom of the shield, I have in another blog android4.0+ lock screen Program development-the key block of the summary, the need for friends to see.

In this blog we mainly discuss how to make an activity appear when the screen is lit, and does not trigger the system lock screen.

"Set your own lock screen page"

First, when the screen is lit, the system emits a broadcast, action_screen_on, we can listen to the broadcast through a broadcastreceiver and start our own activity

For example, the following code:

    Private New Broadcastreceiver () {        @Override        publicvoid  onreceive (context context, Intent Intent) {            = intent.getaction ();             if (Action.equals ("Android.intent.action.SCREEN_ON") | | action.equals ("Android.intent.action.SCREEN_OFF")) {                startactivity (tomainintent);}}    ;

However, light start our activity is not enough, because just start, the system lock screen will still appear in the interface, then the effect becomes, we unlocked the system lock screen to see the custom interface.

This is obviously not what we want to see, we think that when the screen is lit, we can see our interface.

This requirement can be achieved by turning off the system lock screen in the settings of the custom interface.

The code is as follows:

protected void onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);         Final Window win = GetWindow ();        Win.addflags (                |                         WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Unlock the system lock screen         Setcontentview (r.layout.main_layout);        Setview (); // Set Close button    }

With the above settings, we can see our interface when the screen is lit.

An example of a complete lock screen I've uploaded to GitHub with the address: https://github.com/u3shadow/ScreenLockTest

A friend in need can make a reference.

Through these two blog, we can basically implement a lock screen application, on this basis, we can do a further optimization of the custom interface, landscaping, to make their own ideal lock screen.

This series is here, hope to help everyone, thank you

android4.0+ Lock Screen Program development--Set the lock screen page

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.