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

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Redirect User From Browser to My App after open a specific URL without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

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.

We are here to answer your question about Redirect User From Browser to My App after open a specific URL - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji