I am facing problem when url is redirected. I set webviewclient and
It is supposed to finish webview activity when url is redirected.
But it is not working and I wonder why... below is my code and I would be
appreciated if anyone can help me. thx.
public class WebViewActivity extends Activity {
WebView mWebView;
String fbRegsitered = "http://m.facebook.com/gettingstarted/";
//"http://m.facebook.com/r.php?refid=0
String fbUnregisterd = "http://m.facebook.com/r.php?refid=0";
private ProgressDialog mSpinner;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://m.facebook.com/r.php");
mWebView.setWebViewClient(new HelloWebViewClient());
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//view.loadUrl(url);
if(url.contains(fbRegsitered)){
WebViewActivity.this.finish();
}
if(url.startsWith(fbUnregisterd)){
//finish();
}
return true;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…