1.
Pattern wikiWordMatcher = Pattern.compile("(http://|ftp://|https://|www.){0,1}[a-zA-Z0-9\\-\\.]+?\\.(org|edu|uk|hk|com|net|cn|me|tw|fr|be)[^\\s]*"); //定义正则表达式
String mentionsScheme = String.format("%s/?%s=",Constants.MENTIONS_SCHEMA, Constants.PARAM_UID); //格式化字符串,指定跳转意图
Linkify.addLinks(textView, wikiWordMatcher, mentionsScheme); //将TextView的字符串根据正则去替换为链接
2.
然后在清单文件中修改要跳转的Activity的意图
<activity android:name="com.xxx.xx.XxxActivity">
<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="scheme" android:host="host"/>
</intent-filter>
</activity>
3.
然后在跳转的目标页面通过 getIntent().getData().getQueryParameter("key");获取参数后进行处理
ps:意图中可以使用schema://host:port/path?key=value的方式来传递参数
正则表达式在Android应用中的链接跳转实现
本文详细介绍了如何在Android应用中利用正则表达式将文本视图中的链接转换为可点击的链接,并通过配置Activity意图来实现跳转功能。通过实例演示了链接跳转的具体步骤,包括定义正则表达式、格式化字符串、添加链接以及在目标页面获取并处理参数的方法。
1203

被折叠的 条评论
为什么被折叠?



