Webview on Amazon Fire Stick not responding to controller

二次信任 提交于 2019-12-24 09:56:47

问题


I've got an Android app in Cocos2d-x that uses a WebView to display the front end menu. Currently it's just a mock-up, and just has a URL to a website, which makes it easy to test.

If I load the URL of the interface in the Amazon Web App Tester on an Amazon Fire TV stick it works perfectly, and you can navigate the interface happily with the controller.

However, when I load the app on the stick, which shows the same URL in a WebView component then the controller has no effect and doesn't navigate (or even highlight) the interface.

How can I get the WebView to behave like the web view in the tester app, and respond to the controller?


回答1:


In the end the problem was that I needed to call the superclass functions, not return false to indicate I hadn't processed the input. The cocos2d-x GameControllerActivity class isn't set up to cope with this, so I had to modify GameControllerActivity.java and add a new static member/functions to indicate when I wanted my app to have the controller input or if it was OK to pass it on to the WebView to process.

Extra functions:

private static boolean smGrabJoypadInput = false;

public static void grabJoypad() {
    smGrabJoypadInput = true;
}

public static void releaseJoypad() {
    smGrabJoypadInput = false;
}

Modified functions:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

if (!smGrabJoypadInput)
   return super.dispatchKeyEvent(event);
...

@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {

    if (!smGrabJoypadInput)
        return super.dispatchGenericMotionEvent(event);

Then I called these functions via JNI when I needed them.



来源:https://stackoverflow.com/questions/46306492/webview-on-amazon-fire-stick-not-responding-to-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!