gospelslide
gospelslide

Reputation: 179

Intent filter to respond to all URLs in Android?

I want to make an app that involves responding to all the URLs on a device. Documentation mentions how to handle a specific scheme like below-

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

But how do I define an intent filter to handle any URL not just belonging to a particular domain or host? Is it possible?

Upvotes: 2

Views: 1540

Answers (3)

Kudehinbu Oluwaponle
Kudehinbu Oluwaponle

Reputation: 1145

Even though the official android tutorial says you can simply remove the data filter to make your intent-filter less restrictive, doing so might lead to "missing data element" errors. You can do the below instead

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

You can also add data filters for .net, .org etc

Upvotes: 0

J.D.
J.D.

Reputation: 1411

Define Schema 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:scheme="http"/>
    <data android:scheme="https"/>
    <data android:scheme="about"/>
    <data android:scheme="javascript"/>
</intent-filter>

Upvotes: 5

Kelevandos
Kelevandos

Reputation: 7082

Simply remove the below line from the code you posted:

  <data android:host="www.youtube.com" android:scheme="http" />

So you will end up with

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Alternatively, you may want to just shorten the line to

  <data android:scheme="http" />

This will make your app intercept only http URLs, so basically links.

Upvotes: 0

Related Questions