美文网首页
webview loadurl 自动填充

webview loadurl 自动填充

作者: 达布遛 | 来源:发表于2020-12-11 15:18 被阅读0次
    public class ReSetURLUtils {
        public static final String HTTP = "http://";
        public static final String HTTPS = "https://";
        public static final String FILE = "file://";
    
        public static String reSetUrl(String keyword) {
            keyword = keyword.trim();
    
            if (keyword.startsWith("www.")) {
                keyword = HTTP + keyword;
            } else if (keyword.startsWith("ftp.")) {
                keyword = "ftp://" + keyword;
            }
    
            boolean containsPeriod = keyword.contains(".");
            boolean isIPAddress = (TextUtils.isDigitsOnly(keyword.replace(".", ""))
                    && (keyword.replace(".", "").length() >= 4) && keyword.contains("."));
            boolean aboutScheme = keyword.contains("about:");
            boolean validURL = (keyword.startsWith("ftp://") || keyword.startsWith(HTTP)
                    || keyword.startsWith(FILE) || keyword.startsWith(HTTPS))
                    || isIPAddress;
            boolean isSearch = ((keyword.contains(" ") || !containsPeriod) && !aboutScheme);
    
            if (isIPAddress
                    && (!keyword.startsWith(HTTP) || !keyword.startsWith(HTTPS))) {
                keyword = HTTP + keyword;
            }
    
            String converUrl;
            if (isSearch) {
                /*try {
                    keyword = URLEncoder.encode(keyword, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }*/
    //            converUrl = "http://www.google.com/search?q=" + keyword ;
                return null;
            } else if (!validURL) {
                converUrl = HTTP + keyword;
            } else {
                converUrl = keyword;
            }
            return converUrl;
        }
    }
    
    

    相关文章

      网友评论

          本文标题:webview loadurl 自动填充

          本文链接:https://www.haomeiwen.com/subject/zyvjgktx.html