Android lock screen Software production

Source: Internet
Author: User

Reprint please indicate the source http://blog.csdn.net/mingyue_1128

First, to create a service to ensure that service is always on, without being cleaned by a key.

Second, shield off the system lock screen

Third, create lock screen activity, in activity to shield off the Back,menu,home key

Iv. ensure that your process does not appear in recent missions


First, create a service name of Lockservice

public class Lockservice extends Service{private keyguardmanager km;private keyguardlock kk;private broadcastreceiver Broadcastreceiver=new Broadcastreceiver () {@Overridepublic void OnReceive (context context, Intent arg1) {LOG.E ("----- Can jump to the lock screen--------","---------"); Intent intent=new Intent (context,lockactivity.class); Intent.setflags (intent.flag_ Activity_new_task); startactivity (intent);}; @Overridepublic ibinder onbind (Intent arg0) {return null;} @Overridepublic void OnStart (Intent Intent, int startid) {Super.onstart (Intent, Startid);// Service inside received the action to turn off the screen to send broadcast intentfilter ifilter=new intentfilter (Intent.action_screen_off); This.registerreceiver ( Broadcastreceiver, iFilter);} @Overridepublic void OnCreate () {super.oncreate ();//shield off the system's lock screen km= (Keyguardmanager) Getsystemservice (context.keyguard _service); Kk=km.newkeyguardlock (""); Kk.disablekeyguard ();} @Overridepublic void OnDestroy () {Super.ondestroy ();}}

in the service with his cooperation with a broadcast, when the supervisor hears the screen off, the service will send a broadcast, so that the screen when it opens for itself lock screen


Third, the lock screen interface to shield off Menu,home,back

public class Lockactivity extends activity{private static final int flag_homekey_dispatched = 0x80000000;private Button Btn_open; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); This.getwindow (). SetFlags (flag_homekey_dispatched, flag_homekey_dispatched);//Key code Setcontentview (R.layout.activity_main);//Unlock button btn_open= (button) Findviewbyid (r.id.open); btn_ Open.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {finish ();}}); @SuppressWarnings ("Static-access") @Overridepublic boolean onKeyDown (int keycode, keyevent event) {if (keycode==event. Keycode_back) {return true;} if (keycode==event. Keycode_home) {return true;}    if (keycode = = Keyevent.keycode_menu) {//menu key//monitor/Intercept menu key return true; } return Super.onkeydown (KeyCode, event);}} 
ensure that your locker is not present in the recent process, just add a property android:excludefromrecents= "true" when registering the lock screen activity, as follows


       <activity            android:name= "com.mm.wallpaper.LockActivity"           android:launchmode= "SingleInstance           " Android:excludefromrecents= "true" ><intent-filter>                <category android:name= " Android.intent.category.LAUNCHER "/>                <category android:name=" Android.intent.category.DEFAULT "/>            </intent-filter>       </activity>

Iv. We need to look at how the main interface handles

public class Mainactivity extends Activity {mybroadcast receivebroadcast; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);// Register Broadcast receivebroadcast = new Mybroadcast () intentfilter filter = new Intentfilter (); Filter.addaction ("Action"); Only the recipient who holds the same action can receive this broadcast Registerreceiver (receivebroadcast, filter);//Send Broadcast Intent intent=new intent (); Intent.setaction ("action"); This.sendbroadcast (intent);} public class Mybroadcast extends broadcastreceiver{@Overridepublic void onreceive (context context, Intent Intent) { Keyguardmanager km = (keyguardmanager) context.getsystemservice (Context.keyguard_service); Keyguardlock KK = Km.newkeyguardlock (""); Kk.disablekeyguard ();//Start service Intent service=new Intent (); Service.setclass ( Context,lockservice.class);//define Context.startservice (Service) later;}} @Overrideprotected void OnDestroy () {//TODO auto-generated method Stubsuper.ondestroy (); Unregisterreceiver ( receivebroadcast);}}

Here we need to register a broadcast guarantee service to open

Mainactivity requires more than one property in the configuration manifest to ensure that the program always

   <category android:name= "Android.intent.category.HOME"/>


This is probably the whole process, hoping to help a friend who wants to unlock software.

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.