Skip to content

fix(android): forward back key event#13

Open
alexjba wants to merge 1 commit into
masterfrom
fix/forward-back-key-android
Open

fix(android): forward back key event#13
alexjba wants to merge 1 commit into
masterfrom
fix/forward-back-key-android

Conversation

@alexjba
Copy link
Copy Markdown

@alexjba alexjba commented May 21, 2026

Push the back key into the application event loop

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR forwards the Android Back key from the embedded WebView into the Qt/QML event loop so QML can handle back navigation while the WebView has focus.

Changes:

  • Intercept KEYCODE_BACK in the Android WebView and call a new native callback.
  • Add a new JNI entry point that posts synthesized Qt KeyPress/KeyRelease events into the app event queue.
  • Request focus for the WebView when shown to ensure it receives key events.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
mobilewebview/src/android/mobilewebviewbackend_android.cpp Adds JNI callback to post Qt back-key events to the QQuickWindow.
mobilewebview/android/src/org/mobilewebview/MobileWebView.java Intercepts Android back key in the WebView, forwards to native, and requests focus when visible.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +87 to +95
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
if (event.getKeyCode() == android.view.KeyEvent.KEYCODE_BACK) {
if (event.getAction() == android.view.KeyEvent.ACTION_UP) {
withNativePtr(MobileWebView.this::nativeOnBackRequested);
}
return true;
}
return super.dispatchKeyEvent(event);
}
Comment on lines +88 to +93
if (event.getKeyCode() == android.view.KeyEvent.KEYCODE_BACK) {
if (event.getAction() == android.view.KeyEvent.ACTION_UP) {
withNativePtr(MobileWebView.this::nativeOnBackRequested);
}
return true;
}
Copy link
Copy Markdown
Collaborator

@friofry friofry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants