Shudy
Shudy

Reputation: 7936

How to intercept click on specific url and open own webclient -- Android

I'm doing a chat, and In this chat, some messages will be links to a specific url (this url opens a document viewer in the server).

The links look, like this: http://X.X.X.X:8080/DocumentViewer/...

Then I have a webview activity, where I want to open this type of links.

How can "intercept" when the user clicks on this type of links, and open my own webview and not open a "external" browser?

Upvotes: 0

Views: 893

Answers (1)

curob
curob

Reputation: 745

I think that you can accomplish this by creating an intent-filter in your AndroidManifest.xml file for the URL pattern that you are interested in. The documentation for the intent-filter's <data> element shows how you can specify a host and a scheme ("html" in your case) to handle URLs.

This answer shows an example where the developer wanted to handle youtube.com URLs. I have included the manifest snippet below for completeness:

<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>

Based on this, I think (I have not done this myself) that your intent filter should look something like:

<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>

Upvotes: 4

Related Questions