[
https://issues.apache.org/jira/browse/CB-9005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14567197#comment-14567197
]
Ian Darling commented on CB-9005:
---------------------------------
I've got a workaround that is just about suitable for my use case as there's
only two new events ("scanup" and "scandown"), so for people who really are
stuck you can do something about it now without waiting for new functionality.
*I really don't recommed this as a general solution*. It's extremely brittle
and would potentially need to be reimplemented with every Cordova update if the
code changes.
You need a hook in after_platform_add that replaces standard Cordova/CordovaLib
files with replacements (we have one as this allows us to have
source-controlled items that need to go into the platforms/ folder, which we
don't source control itself as we consider platforms a build artifact).
Create a replacement CordovaWebViewImpl.java file that fires "scanup" and
"scandown" events in onDispatchKeyEvent using sendJavascriptEvent.
Create a replacement cordova.js that allows "scanup"/"scandown" in
onMessageFromNative.
Then you can handle those as regular events (which you may need to be careful
with, as you'll get fired a lot of "down" events!)
> Can no longer use setOnKeyListener on webView in plugins
> --------------------------------------------------------
>
> Key: CB-9005
> URL: https://issues.apache.org/jira/browse/CB-9005
> Project: Apache Cordova
> Issue Type: Bug
> Components: Android, Plugins
> Affects Versions: 4.0.0
> Reporter: Ian Darling
> Assignee: Joe Bowser
> Priority: Minor
>
> I have a plugin that is used for handling "physical" key down/up events on
> Android devices with additional buttons - these buttons typically fire off
> KEYCODE_BUTTON_R1, etc
> In earlier versions of Cordova (3.7.0?) I was able to attach a keyListener in
> the plugin by doing:
> this.webView.setOnKeyListener(etc);
> In migrating to 4.0.0 this no longer compiles.
> My initial thought was to change to using
> this.webView.getView().setOnKeyListener instead (which appears to be the
> right way to do it), but this doesn't seem to fully work - my plugin still
> gets volume up/down key events (which I disregard), but not events for
> BUTTON_R1.
> Debugging CordovaLib suggests that CordovaWebViewImpl.onDispatchKeyEvent does
> receive the BUTTON_R1 events, but I'm at a loss as to how to get them into
> the plugin itself.
> Is there a workaround or alternate API I should be using?
> Thanks,
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]