Question

I'm having issues with KeyCodes in my activity that creates a WebView & loads a URL. I've noticed that when I press a key on the keyboard or a button on my IR remote, it does NOT call the onKeyDown() method in the WebView. I'm guessing it directly calls the underlying JavaScript (which is fine as long as the correct keycodes are being passed down)

The problem I'm having is some keys on my IR remote are just being passed down as 0 (like the Guide, Info, the colored buttons which are all used for playback related options). However, some keys do work (such as the numerical buttons). Any idea where the keyCodes are being hijacked? I checked the EventHub & InputDispatcher, they seem to have the right codes. Do I need to check someplace in the chromium/android_webview code base? Here's a snippet of what I'm using:

private class myWV extends WebView
{
    public myWV(Context context)
    {
        super(context);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        Log.e("myWV", "onKeyDown: " +keyCode);
        return super.onKeyDown(keyCode, event);
    }
}


@Override
public void onCreate(Bundle icicle) 
{
    Log.d(TAG, "onCreate");
    Toast.makeText(getApplicationContext(), "Please wait while we look for available TV channels...", Toast.LENGTH_LONG).show();

    super.onCreate(icicle);

    mWebView = new myWV(this);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());

    Log.e(TAG, "onCreate: Calling setJavaScriptEnabled");
    mWebView.getSettings().setJavaScriptEnabled(true);

    mWebView.loadUrl(mURL);

    // Enable the view
    setContentView(mWebView);
}

Would appreciate any tips

Was it helpful?

Solution

Found the piece of code in Chromium that handles key events. Just added my special keys in there & it now works like a charm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top