user1011115
user1011115

Reputation: 1

How to use shouldOverrideKeyEvent to trigger Javascript function

I'm currently building a simpel app for Android with a webview that loads a page that should be controlled from the app. For this, I want to completly override the default keybehaviour, and just call a function with the keycode from the key that is pressed.

For this, I've tried the following

public boolean shouldOverrideKeyEvent(BWWebviewClient view, KeyEvent event){

if ((KeyEvent = KeyEvent.KEYCODE_ENTER)){

webview.loadUrl("javascript:getKeyCode(KeyEvent)");
}

return true;
}

The problem with this is that KeyEvent in my ifstatement cannot be resolved.

What I want to do is simple catch all keys, disable their default behaviour and call a JS function with the keycode as argument.

Can anyone help?

Upvotes: 0

Views: 2060

Answers (1)

Colin Godsey
Colin Godsey

Reputation: 1321

the KeyEvent var doesnt carry from Java to Javascript... what you're using in loadUrl is just a string, and KeyEvent probably exists nowhere in JS.

Upvotes: 1

Related Questions