高通平台短信里面含有中文和ftp开头的网址不能解析

原因:正则表达式没有匹配中文和pft开头的网址
解决方法
修改文件:frameworks/base/core/java/android/util/Patterns.java
里面定义了两个常量

public static final String GOOD_IRI_CHAR =
        "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";

//Match the characters without containing chinese characters private static final String GOOD_IRI_HOST_CHAR =
        "a-zA-Z0-9\u00A0-\u2FFF\u3040-\u4DFF\u9FA6-\uD7FF"
        + "\uF900-\uFDCF\uFDF0-\uFEFF";

根据注释不难理解下面那个匹配表示不支持中文,接下来修改网址匹配规则,最前面增加ftp匹配,然后将GOOD_IRI_HOST_CHAR修改为GOOD_IRI_CHAR即可,修改后代码如下:

public static final Pattern WEB_URL = Pattern.compile(
        "((?:(http|https|Http|Https|rtsp|Rtsp|ftp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
        + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
        + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
        + "(?:" + DOMAIN_NAME + ")"
        + "(?:\\:\\d{1,5})?)" // plus option port number
        + "(\\/(?:(?:[" + GOOD_IRI_CHAR
        + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"  // plus option query params
        + "\\-\\.\\+\\!\\*\\'\\(\\)\\_])|(?:\\,[" + GOOD_IRI_CHAR
        + "])|(?:\\%[a-fA-F0-9]{2}))*)?"
        + "(?:(?=" + FORBIDDEN_CHAR
        + ")|\\b|$)");
        // and finally, a word boundary or end of input. This is to stop
        // foo.sure from matching as foo.su
        // also should remove forbidden characters from end of URL.

你可能感兴趣的:(android,短信,android-网址)