Redirect User From Browser to My App after open a

2019-04-04 14:10发布

问题:

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.

回答1:

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.