I want to create android application which will open url in same application as like facebook application without any browser.
I tried using WebView but it opens the url in browser.
You have to set up a webViewClient for your webView.
Sample code :
this.mWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
Related
I created a WebView App and it's working fine but there is a link which I want it to open in the default browser instead of that app what can I do.
Add a WebViewClient to your webView (if not already added) and then override shouldOverrideUrlLoading () method:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
if (url.contains(myUrl)) {
Intent intent= new Intent(Intent.ACTION_VIEW, myUrl);
context.startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(webview, url);
}
}
}
This way your are telling your webview to not continue loading a specific url. Instead, launch the proper application (mostly a browser) to handle the url.
I want to open links in the same WebView and I've overrided WebView's default web client as following:
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
And it works fine when I'm opening default links, but when I try to open link that was set to open in the new tab nothing is happening. How can I solve this issue ?
You need to override every other link by returning false.
Try return false instead of true
I have a webview that looks like this
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("https://myurl.com/");
webview.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Toast.makeText(LoginActivityWebView.this, url, Toast.LENGTH_SHORT).show();
return false;
}
}
When i change my URL to google everything works great, i can navigate to different sites and everything works.
When I put in my URl it is supposed to link to myurl2, but when I click it the toast prints myurl instead and the page juts reloads (not helpful!).
Any idea as to how this could happen and where shouldOverrideUrlLoading gets its url from?
If i load myurl in a browser and the user clicks a button then it works correctly.
If i load myurl in a webview, but open a browser on links pressed, then when the link is pressed it opens myurl on in a broswer and if you click the button again it correctly opens myurl2 (super weird).
Any ideas?
If the URL is opening in Chrome properly, you should consider adding, webView.getSettings().setJavaScriptEnabled(true) to your code and try again.
You can get the loaded URL from
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
I'm currently developing an application with android WebView.
However, the website has a link that will invoke Skype application.
The link work fine when try with Chrome browser on android, but it return an error when try to open in android WebView. Actually, it gave me an Webpage not Available error.
Any advice?
Regards.
You should check the url that is click/opened in the webview and check if there is an application that handles this kind of urls:
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == skype url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
} else {
view.loadUrl(url);
}
return true;
}
});
I am passing a url into my application and calling loadUrl on a CordovaWebView. Anytime I try with an external URL it opens the link in an external browser application. I need it to remain in my application.
myCordovaWebView.loadUrl("http://google.com");
myCordovaWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}});
myCordovaWebView.loadUrl("http://google.com");