2011-05-02 78 views
0

我有一些大寫字母像http://myserver.com/apps/DroidApp.apk的Android Linkify下殼體URL

當我通過這個網址到Android Linkify一個網址,生成的鏈接的字母大小寫改爲http://myserver.com/apps/droidapp.apk

TextView upgradeLink = (TextView) findViewById(R.id.upgradeNow); 
upgradeLink.setText("Download now."); 
Pattern pattern = Pattern.compile("Download"); 
String scheme = "http://myserver.com/apps/DroidApp.apk+"?action="; 
Log.e(MY_DEBUG_TAG,"Schema URL "+scheme); // printed http://myserver.com/apps/DroidApp.apk?action= 
Linkify.addLinks(upgradeLink, pattern, scheme); 

哪有我過來了嗎?

回答

3

內部,Linkify呼籲

public static final boolean addLinks(Spannable s, Pattern p, String scheme, null, null) 

檢查code for that method

public static final boolean addLinks(Spannable s, Pattern p, 
     String scheme, MatchFilter matchFilter, 
     TransformFilter transformFilter) { 
    boolean hasMatches = false; 
    String prefix = (scheme == null) ? "" : scheme.toLowerCase(); // <-- here is the problem! 
    Matcher m = p.matcher(s); 

    while (m.find()) { 
     int start = m.start(); 
     int end = m.end(); 
     boolean allowed = true; 

     if (matchFilter != null) { 
      allowed = matchFilter.acceptMatch(s, start, end); 
     } 

     if (allowed) { 
      String url = makeUrl(m.group(0), new String[] { prefix }, 
           m, transformFilter); 

      applyLink(url, start, end, s); 
      hasMatches = true; 
     } 
    } 

    return hasMatches; 
} 

擴展Linkify和重寫此方法,去除scheme.toLowerCase()位。