Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old October 14th, 2011, 10:24 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default shouldOverrideKeyEvent doesn't work on webview

Code:
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebView;
import android.widget.Toast;
import android.webkit.WebViewClient;
public class BWinBrowserActivity extends Activity { 
WebView webview;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl("");   
    } 
public boolean uiOverrideKeyEvent(KeyEvent event) {  
if (webview != null) {  
return webview.shouldOverrideKeyEvent(webview, event);  
}  
return false;  
} 
}
I have the following code. I'm trying to disable the complete default keyhandling by the webview component (the complete keyhandling is done by the loaded webpage in javascript).

However, the shouldOverrideKeyEvent isn't working. Eclipse 3.5.2 return 'the method shouldOverrideKeyEvent is undefined for the type Webview'.
However, if I check the Android documentation, it says shouldOverrideKeyEvent is a method of WebView.

How to fix this?

TERW_DAN is offline  
Reply With Quote
sponsored links
Old October 17th, 2011, 09:56 PM   #2 (permalink)
Developer
 
stevealbright's Avatar
 
Join Date: Apr 2011
Location: York, PA
Gender: Male
Posts: 253
 
Device(s): Nexus 5, Nexus 7 (2012 IO), Nexus 10, HTC One, Samsung Tab 10.1, Samsung Galaxy Nexus, HTC Thunderbo
Carrier: T-Mobile

Thanks: 146
Thanked 287 Times in 130 Posts
steve.albright@gmail.com
Default

I think what your looking to do is use the method shouldOverrideKeyEvent for a WebViewClient rather then what your currently doing with a WebView. A WebView does not contain the public method shouldOverrideKeyEvent.

Hope that helps.

Steve
stevealbright is offline  
Reply With Quote
Old October 24th, 2011, 05:33 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I use it on the webviewclient it seems to generate a bit less errors, but still it doesn't work (since there is no documentation on this, it is pretty hard to get it working).

What I want to do is to catch every key, disable its default behaviour and send the keycode to a JS function, so I can handle the key in JS.

Code:
    public boolean shouldOverrideKeyEvent(BWWebviewClient view, KeyEvent event){
    
if ((KeyEvent = KeyEvent.KEYCODE_ENTER)){
    
webview.loadUrl("javascript:getKeyCode(KeyEvent)");
}
    
return true;
    }
If I try to execute the code, it keeps nagging KeyEvent cannot be resolved in my if-statement. I have no clue why, since it can be found 1 rule above that, in the public boolean declaration.

Can anyone help me on how to override a key, disable its default behaviour and then calling a JSfunction on my webpage, with the keyeevent?
TERW_DAN is offline  
Reply With Quote
Reply
Tags
shouldoverridekeyevent, webview


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:48 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.