How does Android press a preset hardware button on any interface to enter an Activity?

Source: Internet
Author: User

 

 

Enables you to enter an Activity by pressing a preset button on any non-lock screen interface.

Modify the following methods in the alps/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager. java file:

Public long interceptKeyBeforeDispatching (WindowState win, KeyEvent event, int policyFlags)

Find the following code snippet:

Else if (keyCode = KeyEvent. KEYCODE_APP_SWITCH ){

If (down & repeatCount = 0 &&! KeyguardOn ){

Showorhiderecent1_dialog (recent_assist_behavior_show_or_dismiss );

}

Return-1;

}

Add the corresponding code after this else if:

Else if (keyCode = KeyEvent. KEYCODE_APP_SWITCH ){

If (down & repeatCount = 0 &&! KeyguardOn ){

Showorhiderecent1_dialog (recent_assist_behavior_show_or_dismiss );

}

Return-1;

} // Add begin

Else if (keyCode = KeyEvent. KEYCODE_XXX ){

If (down & repeatCount = 0 &&! KeyguardOn ){

MContext. startActivity (new Intent (intent. xxx). addFlags (Intent. FLAG_ACTIVITY_NEW_TASK ));

}

Return-1;

} // Add end

 

Note:

1. The KeyEvent. KEYCODE_XXX written above is the pre-set key value of the hard key. You can set it as needed;

2. In startActivity (new Intent (intent. xxx), intent. xxx needs to be written according to the started activity.


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.