Redirect User From Browser to My App after open a specific URL

esmaeil picture esmaeil · Nov 23, 2015 · Viewed 18.6k times · Source

I wrote an application that user after click on buy Button He/She redirect to Internet Browser (e.g: chrome) and after payment I want he come back to my App (my activity) so I found out that I should use Intent-Filter but It doesn't work for me!

I add these codes in manifest:

<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="returnApp" android:scheme="myapp"></data>
</intent-filter>

And when I open a url like this:

myapp://returnApp?status=1

my app doesn't open.

Answer

pepyakin picture pepyakin · Nov 23, 2015

Try to open it like myapp://returnApp/?status=1 (add trailing slash character). This is happens because path parameter is defined with default value of /.

Unfortunately, you can't match exactly for empty string. As documentation states:

The path part of a URI which must begin with a /.

If you are really need to start app with exactly url myapp://returnApp?status=1 you can add android:pathPattern=".*" parameter to your data clause like

<intent-filter>
    ...
    <data android:host="returnApp" android:scheme="myapp" android:pathPattern=".*"></data>
</intent-filter>

Intent filter with data android:pathPattern=".*" will match for any paths including empty one.