All Products
Document Center

Interpret physical button by using H5 Container

Last Updated: Sep 01, 2021

To intercept physical button by using H5 Container, you need to upgrade the mPaaS baseline version to or later. Set the Provider intercepted by the physical back button with the following codes.

  1. public interface MPH5OnKeyDownProvider {
  2. boolean needIntercept(H5Page page, int keyCode, KeyEvent intent);
  3. boolean onKeyDown(H5Page page, int keyCode, KeyEvent intent);
  4. }

If the interception operation is to be excuted, set the return value of needIntercept to true, automatically execute the onKeyDown method, and no longer execute the mPaaS physical back button logic. If needIntercept returns false, it means that the physical back button event is returned to the original mPaaS logic for processing, and the onKeyDown method is no longer executed.

Note: When executing the needIntercept method and the onKeyDown method, it is necessary to check whether the parameter value is null.