0

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>
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80

1 Answers1

1

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.

Community
  • 1
  • 1
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • It doesn't work. this is the error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference – Alireza Noorali Jan 08 '17 at 07:26
  • Known bug. It occurs when you're attempting to use something that requires GooglePlayServices on a device without it installed. WHat you're doing that requires it I have no idea, since nothing discussed in this question needs it. – Gabe Sechan Jan 08 '17 at 07:33