Android: beat the system and listen for the Home Key.

Source: Internet
Author: User


1760 reading comments (13)
Favorites
Report

This is an android study note about the home key.

Proposal of proposal

The android HOME key system is responsible for monitoring and automatically processes the captured data. Sometimes, the processing of the system often does not mean anything. What should we do if we want to handle the event after clicking home on our own?

 

Solution to the Failover Problem

Disable the Home key first, and then process the key value in onkeydown. When you click the Home Key, close the program or follow your xxoo.

 

@ Override

Public
Boolean onkeydown (INT keycode, keyevent event)

{// Todo auto-generated method stub

If (keyevent. keycode_home = keycode)

Android. OS. process. killprocess (Android. OS. process. mypid ());

Return
Super. onkeydown (keycode, event );

}

 

@ Override

Public
Void onattachedtowindow ()

{// Todo auto-generated method stub

This. getwindow (). settype (windowmanager. layoutparams. type_keyguard );

Super. onattachedtowindow ();

}

 

 

Add the permission to prohibit the Home Key

<Uses-Permission Android: Name = "android. Permission. disable_keyguard"> </uses-Permission>

This is an android study note about the home key.

Proposal of proposal

The android HOME key system is responsible for monitoring and automatically processes the captured data. Sometimes, the processing of the system often does not mean anything. What should we do if we want to handle the event after clicking home on our own?

 

Solution to the Failover Problem

Disable the Home key first, and then process the key value in onkeydown. When you click the Home Key, close the program or follow your xxoo.

 

@ Override

Public
Boolean onkeydown (INT keycode, keyevent event)

{// Todo auto-generated method stub

If (keyevent. keycode_home = keycode)

Android. OS. process. killprocess (Android. OS. process. mypid ());

Return
Super. onkeydown (keycode, event );

}

 

@ Override

Public
Void onattachedtowindow ()

{// Todo auto-generated method stub

This. getwindow (). settype (windowmanager. layoutparams. type_keyguard );

Super. onattachedtowindow ();

}

 

 

Add the permission to prohibit the Home Key

<Uses-Permission Android: Name = "android. Permission. disable_keyguard"> </uses-Permission>

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.