2016-04-28 75 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>