Implement custom lock screen control in Android

Source: Internet
Author: User

To implement custom screen lock on Android phones, you often need to unlock the screen lock before entering the custom screen lock interface to smoothly enter the custom screen lock interface, it also facilitates other operations in real time. The following code is used to implement this function:

1. Enable the screen and unlock the system lock
//light the screen PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);   WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP    | PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer");   mWakelock.acquire();   mWakelock.release();    //unlock the screenKeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);  KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");  keyguardLock.disableKeyguard(); 
2. Add Permissions

To enable the automatic screen unlocking function of the above Code, you also need to add permissions in the main configuration file androidmanifest. xml:

<uses-permission android:name="android.permission.WAKE_LOCK" />      <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
3. General idea of implementing the custom lock screen control system

(1) Design a screen lock control button on the main interface to determine whether to enter the custom screen lock control interface;

(2) You need to design a service. At startup, register the broadcast behavior action_screen_off: "android. Intent. Action. screen_off" to listen to the screen lock of the system in the oncreate method ";

(3) define a broadcast receiver in the preceding serice: If action_screen_off is monitored, the custom screen lock control interface is used to start the custom activity;

4. Difficulties

(1) action_screen_off the message must be dynamically registered and cannot be registered globally in the XML file.

(2) After receiving the screen_off message, how can I make the screen lock interface defined by myself on the System screen lock interface?

(3) how to prevent the pop-up screen when the screen is lit

(4) Some models may need to light up the screen twice.

(5) unlock the system lock first when you unlock the custom lock.

(6) How to Implement compatibility under multi-model multi-ROM when unlocking the system

(7) How to Prevent force control on the headset or other related behaviors after unlocking the system?

(8) how to restore the system lock in time after unlocking the system lock

(9) How to ensure that your lockscreen is on top of all other lockscreens when other third-party lockscreen systems exist.

(10) How to shield related buttons on the screen lock interface, especially the Home Key, especially on the 4.0 system

5. Summary

Simple implementation of custom lock screen, I think most people can achieve it in a short time, the key is to integrate it into the third application to ensure that it is compatible with most models and Rom, that is to solve the difficulties mentioned above. For example, you can implement screen lock functions similar to everyday sounds and cool dogs.

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.