在与Android的WebView浏览器中打开外部链接在与、器中、链接、WebView

2023-09-04 05:15:21 作者:丅1站丶永遠

我有这个code,但不是因为它的工作原理,它不断开放的WebView什么,我想要的是链接不属于我的网站在默认浏览器打开。任何想法?谢谢

 私有类CustomWebViewClient扩展WebViewClient {
        @覆盖
            公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
              如果(url.contains(message2space.es.vu)){
                view.loadUrl(URL);
                返回true;
            }其他{
                返回super.shouldOverrideUrlLoading(查看,网址);
            }

            }
        }
 

解决方案

现在的问题是,你需要发送的意图到默认的Web浏览器打开链接。你在做什么只是调用你的web视图处理的链接不同的方法。每当你想另一个应用程序来处理的东西你需要使用意图。试试这个code来代替。

 私有类CustomWebViewClient扩展WebViewClient {
        @覆盖
            公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
              如果(url.contains(message2space.es.vu)){
                view.loadUrl(URL);
              } 其他 {
                意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(URL));
                startActivity(ⅰ);
              }
              返回true;
            }
        }
 

Android 基于腾讯 X5 内核的 WebView 超级浏览器 ,拥有文件上传 下载 浏览 支持 PDF PPT DOC EXCEL TXT 格式 Android 与 JS 的交互 视频播放 自

I have this code, but not because it works, it keeps opening in webview and what I want is that the links do not belong to my website open in your default browser. Any idea? thanks

private class CustomWebViewClient extends WebViewClient {
        @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if(url.contains("message2space.es.vu")){
                view.loadUrl(url);
                return true;
            }else{
                return super.shouldOverrideUrlLoading(view, url);
            }

            }
        }

解决方案

The problem is you need to send an Intent to the default web browser to open the link. What you are doing is just calling a different method in your Webview to handle the link. Whenever you want another app to handle something you need to use Intents. Try this code instead.

private class CustomWebViewClient extends WebViewClient {
        @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if(url.contains("message2space.es.vu")) {
                view.loadUrl(url);
              } else {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
              }
              return true;
            }
        }

 
精彩推荐
图片推荐