Alireza Noorali
Alireza Noorali

Reputation: 3265

How to make a the links of my website in the Android browser start up my app but not when the link has a Certain part

I'm going to implement this scenario:

www. example.com -> Start up my App

http:// example.com -> Start up my App

http:// www.example.com -> Start up my App

https:// example.com -> Start up my App

https:// www.example.com -> Start up my App

But...

http:// example.com/dont/start/app -> Open the link in default browser.

by using intent-filter all the times it will open my app.

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <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:host="example.com" />
        </intent-filter>
    </activity>

Upvotes: 0

Views: 67

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93678

One way to do it would be to open the browser directly in that case. Like this

onCreate() {
  if(uri is in path we don't want) {
    open browser directly via intent
    finish();
    return;
  }
  //Handle a URL we do want
}

To open the browser directly, you can figure out what the default browser is via How to find default browser set on android device and launch it explicitly.

Upvotes: 1

Related Questions