Reputation: 8674
I want to load a separate URL in place of incoming URL in android. What i am doing is following :
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.contains("http://google.com")) {
url = url + "&ru=https://google.com/getTicket";
return super.shouldInterceptRequest(view, url);
}
return super.shouldInterceptRequest(view, url);
}
But this is not loading the new URL. What should i do to load new URL??
Upvotes: 0
Views: 92
Reputation: 4324
You can do it with setting setWebViewClient
with your webview
.
mWebView.setWebViewClient(new myWebClient());
// Javascript inabled on webview
mWebView.getSettings().setJavaScriptEnabled(true);
//Load url in webview
mWebView.loadUrl("http://www.google.com");
webClient code
public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (mProgressBar != null)
mProgressBar.setVisibility(View.GONE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://www.google.com")) {
System.out.println(url);
// Load your custom URL
mWebView.loadUrl(url + "&ru=https://google.com/getTicket");
return true;
}
return false;
}
}
Upvotes: 1
Reputation: 101
mWidgetWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("http://google.com")){
view.loadUrl(url + "&ru=https://google.com/getTicket");
return true;
}
return false;
}
}
Try this code, it should work.
when url contains 'http://google.com', load another url and return true.
Upvotes: 1