Skip to content

Commit

Permalink
Handle all links within the WebView itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratul Kalia committed Nov 2, 2011
1 parent 447b2db commit 5159692
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/in/prtk/navalgund/Navalgund.java
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.