Support for other protocols in the Android web browser

I created an application for web browsing, on a page on which market: // links functions are displayed, but after clicking on them I get a 404 screen along with an error that the protocol is not supported. I tried to look at the documentation, but could not find anything related to this. Any help is greatly appreciated.

+18
android android-webview uri-scheme custom-url
Aug 27 '10 at 10:27
source share
6 answers

For me, the JavaScript problem was not a solution, since HTML is not under my control. Therefore, if you need to control this from the side of the application, then there is a relatively simple solution: to deduce from WebViewClient and implement the implementation using WebView.setWebViewClient() . All you need to override in your WebViewClient implementation is the WebViewClient method, as shown below:

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

It works great for me.

+37
Apr 01 2018-11-11T00:
source share

For links to work, you must have installed the application on your device / emulator. Your application must also request permission to access the network.

UPD: as a workaround, you can call java code from a web view, for example, if you create such links:

 <a href="javascript:go('market://your.path.to.market.app')">..</a> 

Define a javascript function called go ():

 <script type="text/javascript"> function go(link) { if (handler) { handler.go(link); } else { document.location = link; } } </script> 

Then you can pass the handler object to the WebView:

 webview.addJavascriptInterface(new Handler() { @Override public void go(String marketUrl) { //start market intent here } }, "handler"); 

The handler interface can be defined as follows:

  public interface Handler{ public void go(String url); } 
+1
Aug 27 '10 at 10:53 on
source share

HOPE IT 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; } } 
+1
Jan 09 '15 at 15:00
source share

Work with 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; } } } 
0
Feb 03 '15 at 17:01
source share

It is important to understand how web browsing and its clients (webviewclient and webchromeclient) work. Please view http://therockncoder.blogspot.in/2014/04/understanding-androids-webchromeclient.html

In the webviewclient shouldOverrideUrlLoading () method, you can decide whether you want to open the link in a new browser or in web browsing. If you do not override this method, it will by default open a link in a new browser outside of your Android application. If you want to open in webview, override the method as shown 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 automatically open the corresponding applications if they are opened outside the web browser, and if this application is installed on the phone.

If you want to open certain links in a web browser and certain schemes outside of web browsing, you need to override the WebChromeClients onCreateWindow () method, as described in the link above. He must solve this problem.

0
Jul 24 '15 at 7:26
source share

Simplest solution

  Intent newApp = new Intent(Intent.ACTION_VIEW, Uri.parse(URL)); startActivity(newApp); 
-2
Apr 23 '13 at 6:13
source share



All Articles