application is not intercepting url

2019-07-31 10:13发布

I am trying to intercept my own app's URL on android so that the user can open the URL in the app rather than on the browser. (I don't have browser support yet).

This is what I'm doing

<activity android:name=".ui.activity.MainActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.PICK_ACTIVITY" />
        <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:host="myapp.com" />
        <data android:pathPattern=".*"/>
    </intent-filter>
</activity>

For some reason anytime I open myapp.com it still keeps opening in the browser, without giving me the option to open the URL in my app. I am trying this on my emulator with API 16 running on it. I've closed the emulator several times and started it again but still its the same behavior.

To avoid any errors in the URL of my personal app. I even experimented with:

         <data android:host="goo.gl" android:scheme="http" />
         <data android:host="goo.gl" android:scheme="https" />

The app DOES intercept the above url but ONLY the first time. If I click 'JUST ONCE' in the options presented, I don't get the option ever again until I restart the emulator.

Has anyone gone through this? What might I be doing wrong?

1条回答
叼着烟拽天下
2楼-- · 2019-07-31 10:54

this answer helped me : link to question

if you add the package name to the intent, it will open your app by default

查看更多
登录 后发表回答