FBI Warning: Welcome reprint, but please indicate source: http://blog.csdn.net/codezjx/article/details/45485975 , do not use for commercial purposes without my consent, thank you for your support!
(1) Shielded return key : Override onbackpressed () to not call the superclass method
@Overridepublic void onbackpressed () {//super.onbackpressed ();}
(2) Shielded home button:
1, the general method is as follows: (But in Android4.0 above will fail )
@Overridepublic void Onattachedtowindow () {This.getwindow (). SetType (WindowManager.LayoutParams.TYPE_KEYGUARD); Super.onattachedtowindow ();}
and add Permissions:
<uses-permission android:name= "Android.permission.DISABLE_KEYGUARD" ></uses-permission>
< Span class= "style=" Color:rgb (51,51,51); Font-family:georgia; letter-spacing:0pt; Font-weight:bold; Font-size:12pt "> 2, Android4.0 above the shielding method : (more wretched, but in 4.4 or above will fail )
Use the WindowManager AddView method to add the view to the window, plus the view's Layoutparamas TYPE is set to Layoutparams.type_system_error.
and add Permissions <uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>
< Span class= "style=" Font-family:georgia; Color:rgb (51,51,51); letter-spacing:0pt; Font-weight:bold; Font-size:12pt "> principle: use WindowManager to add a layer of view to the front of the screen And make its TYPE set to: Layoutparams.type_system_error, the official explanation for it is: internal system error windows, Appear on top of everything they can, both displayed on any interface. and set flags to layoutparams.flag_not_touchable so that we can listen to touch events and paint on the back layer of the annotation brush. Then we can set the add view is an empty view, you will not feel the front of a layer of things, so as to achieve the effect of shielding the home button.
< Span class= "style=" Font-family:georgia; Color:rgb (51,51,51); letter-spacing:0pt; Font-weight:bold; FONT-SIZE:12PT "> reference code:
private void Forbiddenhomekey () {Mwindowmanager = This.getwindowmanager (); mwindowmanagerparams = new Layoutparams (); Mwindowmanagerparams.width = Layoutparams.wrap_content;mwindowmanagerparams.height = LayoutParams.WRAP_CONTENT; Internal system error windows, appear on top of everything they canmwindowmanagerparams.type = Layoutparams.type_system _error; Indicate this view don ' t respond the touch Eventmwindowmanagerparams.flags = layoutparams.flag_not_touchable;//Add an Empty view on the top of the Windowmemptyview = new View (this); Mwindowmanager.addview (Memptyview, mwindowmanagerparams);}
3, about the shield of home, there is a way of thinking
(requires system permissions)
:
< Span style= "Font-family:georgia; Color: #333333 "> listener is displayed in the foreground (via Activitymanager.getrunningappprocesses ()), if not, Immediately move the program's task to the foreground (via Activitymanager.movetasktofront () ). But Android has long thought of this loophole, when you finish clicking the Home button, the system's launcher will have 5 seconds of delay protection. All methods that start the activity or move to the foreground will have a 5-second delay. Specifically see stackoverflow "answer, If you need to crack this limit you need to add the system permission "Android.permission.STOP_APP_SWITCHES" :
http://stackoverflow.com/questions/5600084/ Starting-an-activity-from-a-service-after-home-button-pressed-without-the-5-seco
In other words, if there is no system permissions, can only be written by their own third-party launcher can be cracked, this method through the master himself pro-test effective!
Back key and home key masking