To intercept physical button by using H5 Container, you need to upgrade the mPaaS baseline version to 10.1.68.33 or later. Set the Provider intercepted by the physical back button with the following codes.
public interface MPH5OnKeyDownProvider {
boolean needIntercept(H5Page page, int keyCode, KeyEvent intent);
boolean onKeyDown(H5Page page, int keyCode, KeyEvent intent);
}
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.