java - Adding override for onKeyLongPress in Android Phonegap plugin -


I'm not even familiar with writing plugins for Android, though I implement a long press function for the hardware search button Want me in my Cordoba application

I can successfully do this like this:

  Public class MyelCardCordova Attachivity {@Override public void onCreate {bundle saved instenstate} {super.onCreate savedInstanceState) ; Super.init (); // set & lt; content src = "index.html" /> Config.xml in super.loadUrl (Config.getStartUrl ()); //super.loadUrl(file:///android_asset/www/index.html "); } @ Override Public Boolean on KellungPress (Int kikod, Key Event Event) {if (keycode == KeyEvent.KEYCODE_SEARCH) {reference cntx = getApplicationContext (); Toast. Maketext (CNTX, "Long Press", Toast. LNNGHHORT). Show (); Back true; } Return SuperConnLongpress (keycode, event); }}   

but I'm looking for a way to supply onKeyLongPress override in a plugin and not directly editing MyClass.java POC).

The way I understand it, it should be overridden to Myclass, and no Cordova activity.

I know that someone can add an event listener like this:

  document.addEventListener (how can I do this) "searchbutton", function (e) {// dot stop}, false);   

However my requirement is a long press.

I have tried the following:

Creating my plugin and trying to expand my app's class:

  Public Class MyPlugin Expands MyClass {@Override Public boolean onKeyLongPress (int keyCode, KeyEvent event) {if (keycode == KeyEvent.KEYCODE_SEARCH) {reference cntx = getApplicationContext (); Toast. Maketext (CNTX, "Long Press", Toast. LNNGHHORT). Show (); Back true; } Return SuperConnLongpress (keycode, event); }}    

Creating your plugin and trying to increase cordova attractivity:

  Public class Mylglin Cordova activity Increases {@Override public boolean onKeyLongPress (int keycode, keyEvent event) {if (keycode == KeyEvent.KEYCODE_SEARCH) {reference cntx = getApplicationContext (); Toast. Maketext (CNTX, "Long Press", Toast. LNNGHHORT). Show (); Back true; } Return SuperConnLongpress (keycode, event); }}   

Any pointers will be appreciated.

I thought I would post my answer here if anyone has the same problem.

What did I need to do the following:

  private void bindKeyEvents () {This.WebView.setOnKeyListener (see new. OnKeyListener () {@ Override Public Boolean Onki (see V, Int kikod, Key Event Event) {if (keycode == KeyEvent.KEYCODE_SEARCH) {if (event.getAction () == KeyEvent.action_up} {Log D. ("TestAp", "Release"); Return True;} if (event.get action () == key event.action_down and event.uslogpress ()) {log D. ("testpay", "long press"); actual truth;} if (event.getAction () = = KeyEvent.ACTION_DOWN) {event.startTracking (); log Shri. ( "Testapp", "Press"); the real truth;}} return true;}}); }   

And called the bindKeyEvents method from your plugin.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -