2016-04-28 78 views
0

我正在做一个聊天,并在这个聊天中,一些消息将链接到特定的URL(此URL打开服务器中的文档查看器)。如何拦截点击特定的URL并打开自己的webclient - Android

的联系看,像这样:http://X.X.X.X:8080/DocumentViewer/...

然后,我有一个网页流量的活动,在这里我想打开这种类型的链接。

当用户点击这种类型的链接并打开我自己的webview并且不打开“外部”浏览器时,如何“拦截”?

+0

ListView显示你的对话?如果是的话,它可能很丑,但你可以在ListView上设置一个onItemClickListener并解析消息。 –

回答

2

我认为,你可以通过在AndroidManifest.xml文件,你有兴趣在URL模式创建intent-filter做到这一点。对于文档intent-filter的< data>元素展示了如何指定hostscheme (在你的情况下是“html”)来处理URL。

This答案显示了开发人员想要处理youtube.com网址的示例。我已经encluded清单片段下方的完整性:

<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:host="www.youtube.com" android:scheme="http" /> 
</intent-filter> 

在此基础上,我觉得(我没有这样做我自己),你的意图过滤器应该是这个样子:您是否使用了

<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:host="http://X.X.X.X:8080/DocumentViewer/" android:scheme="http" /> 
</intent-filter>