Textview has its own property Android: autolink = "Web". setting this property allows android to automatically identify the URL and click it to open it. However, this is the default browser to jump, we hopeProgram. At this time, we need to use linkify.
Private Static final string schema = "com. Youku. javaske: // message_private_url"; Private Static final string param_uid = "uid ";
Private void extracturl2link (textview v) {pattern wikiwordmatcher = pattern. compile ("(HTTP \: \/) | (HTTPS \: \/) | (www \\.)) [a-zA-Z0-9 _ \.] +) "); string mentionsscheme = string. format ("% S /? % S = ", schema, param_uid); linkify. addlinks (v, wikiwordmatcher, mentionsscheme );}
AboveCodeIt is our processing of textview, where pattern is used to identify the URI. Here we will identify the URI starting with HTTP, https, and www.
Then we write another activity to respond to the click event of textview.
Register the activity in androidmanifest. xml. The Code is as follows:
<Activity Android: Name = "mentionsactivity">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. View"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
<Data Android: Scheme = "com. Youku. mongoke" Android: host = "message_private_url"/>
</Intent-filter>
</Activity>
Then process the uploaded URI in this activity. The Code is as follows:
Private Static final string schema = "com. youku. required KE: // message_private_url "; Private Static final string param_uid =" uid "; Private Static final URI profile_uri = Uri. parse (schema );
Private void extractuidfromuri () {URI uri = getintent (). getdata (); If (Uri! = NULL & profile_uri.getscheme (). equals (URI. getscheme () {uid = Uri. getqueryparameter (param_uid);} If (UID. indexof ("www") = 0) {uid = "http: //" + uid;} else if (UID. indexof ("HTTPS") = 0) {string buid = uid. substring (5, uid. length (); uid = "HTTP" + buid ;}}
UID is the URI address we get. At this time, we can get it through webview based on the network address.
The following is a demo on csdn.
Http://download.csdn.net/detail/liuhanhan512/5441679