Cannot open skype custom URL from android WebView - android

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;
}
});

Related

How can i make a link to open in browser instead of WebView App

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.

How to open a web browser in WebView app when an external link is clicked?

I want to open external links in web browser using intent and should not open in my WebView app except my internal links starts with "https://www.ecommerce.in/"
I have written code as given below:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (!url.contains("https://www.ecommerce.in/"))
{
Uri uri = Uri.parse(url);
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
view.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
} else {
webViewProduct.loadUrl(url);
return true;
}
}
This code is working perfectly as I want but the problem is when I pressed back button on web browser the same external link is opening in my WebView app.
Please let me know where I'm doing wrong. Thanks in advance.
You should have to remove view.loadUrl(url) from you code , So
Please replace your code as given below
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (!url.contains("https://www.ecommerce.in/"))
{
Uri uri = Uri.parse(url);
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
CookieManager.getInstance().setAcceptCookie(true);
} else {
webViewProduct.loadUrl(url);
return true;
}
}

Facebook share button in Android Application

FB share button could successfully oepn the FB messenger app in Chrome browser.
However, the same source code, it fail to open the FB messenger app if display in Android APP application, and this application display web page using Chrome browser inside.
How to fix it?
You could provide a custom WebViewClient implementation to your WebView that checks for facebook.com links (or whatever links you like) and then explicitly fire an Intent so others can pickup the Action, instead of allowing the WebView to handle it as it sees fit.
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Uri uri = Uri.parse(url);
if (uri.getHost().contains("facebook.com")) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
return false;
}
} catch(Exception e){
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}
});

Android Webview URL redirect on some Devices doesn´t work

I use a Android Webview and Override the Url Loading:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
On a Logout i have the following URL: https://someadress/logout?redirectURL=https%3A%2F%2Fsomeadress.de%2Flogout.html&skinID=no_scr
On some Devices, specially Samsung Devices, the redirect is not working and stops after calling this URL. But on the most Devices the redirect is working.
Anybody has some Idea why the redirect isn´t working on some Kind of Devices?
Try this on. This is working fine for me
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(i);
return true;
}
You are loading the same URL. That is not an override. If you are returning true, you need to load a different URL.

Support for other protocols in Android webview

I've created a web view app, the page that is displayed features market:// links but upon clicking them I get the 404 screen along with the error that the protocol is not supported. I've tried looking through documentation but was unable to find anything relating to this. Any help is much appreciated.
For me the JavaScript thing wasn't a solution as the HTML is not under my control. So if you need to control this from the application side, then there is a relative simple solution: Derive from WebViewClientand inject the implementation using WebView.setWebViewClient(). All you need to override in your WebViewClientimplementation is the shouldOverrideUrlLoading method as shown here:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("market://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
For me this works fine.
HOPE THIS HELPS YOU
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.startsWith("market://")||url.startsWith("vnd:youtube")||url.startsWith("tel:")||url.startsWith("mailto:"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
else{
view.loadUrl(url);
return true;
}
}
For the links to work you have to have the market app installed on your device/emulator.
Also your app need to request a permission to access network.
UPD:
as a workaround you can call java code from within the webview, for example if you generate links like this:
..
Define a javascript function named go():
<script type="text/javascript">
function go(link) {
if (handler) {
handler.go(link);
} else {
document.location = link;
}
}
</script>
You then can pass in a handler object into the WebView:
webview.addJavascriptInterface(new Handler() {
#Override
public void go(String marketUrl) {
//start market intent here
}
}, "handler");
Handler interface can be defined as follows:
public interface Handler{
public void go(String url);
}
Work for me:
webView = (WebView) findViewById(R.id.webView);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.setWebViewClient(new MyWebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://myweb.com");
private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("whatsapp://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
}
It is important to understand how the webview and its clients (webviewclient and webchromeclient) works. Please go through the http://therockncoder.blogspot.in/2014/04/understanding-androids-webchromeclient.html
In the webviewclient's shouldOverrideUrlLoading() method, you can decide if you want to open the link in new browser or within the webview. If you don't override this method, it will by default open the link in a new browser outside of the your android application.
If you want to open within webview, override the method as below
public boolean shouldOverrideUrlLoading(WebView view, String url) { <br>
Log.v("activity", "INSIDE WEBVIEW CLIENT ON shouldOverrideUrlLoading");
view.loadUrl(url);
return false; //need to understand return value based on usage
}
Schemes like whatsapp://send?text=Hello%20World! or market://details?id=xx.xx.xx will open the corresponding apps automatically if they are opened outside the webview and if that app is installed on the handset.
If you want to open certain links within webview and specific schemes outside webview, you need to override WebChromeClients onCreateWindow() method as explained in the link provided above. It should solve the purpose.
Instead of adding check for particular scheme, Modifying #sven solution, this will work for all schemes
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String host= Uri.parse(url).getHost();
if (host == null) {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
view.loadUrl(url);
return false;
}
Simplest solution
Intent newApp = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(newApp);

Categories

Resources