Skip to content
Browse files

Handle all links within the WebView itself.

  • Loading branch information...
1 parent 447b2db commit 5159692b7f7c7092b4019893a2dc23c886ccc860 @lut4rp committed Nov 3, 2011
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/in/prtk/navalgund/Navalgund.java
View
21 src/in/prtk/navalgund/Navalgund.java
@@ -2,6 +2,7 @@
import android.app.Activity;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
@@ -19,6 +20,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
wv = (WebView) findViewById(R.id.webview);
+ wv.setWebViewClient(new HelloWebViewClient());
wv.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
@@ -38,4 +40,23 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
wv.loadUrl("http://27.7.20.190/~prateeksaxena/game/");
}
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
+ wv.goBack();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+
+ private class HelloWebViewClient extends WebViewClient {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ view.loadUrl(url);
+ return true;
+ }
+ }
+
}

0 comments on commit 5159692

Please sign in to comment.
Something went wrong with that request. Please try again.