Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect url to app android

I want the callback of an oauth2 authentication to redirect to my app. I know about chrome's intent filter but it requires the user to manually ask the app to open. I read on the internet it's not possible to do it automatically but apps like Instagram or even Google's IO app have the ability to be open from the browser (here are some examples https://instagram.com/_u/instagram and https://events.google.com/io/schedule). I've also tried intent filters (in the manifest) but them don't work either. I don't require the app to be triggered by the callback url in the oauth, if needed I could use a backend. How do I achieve that?

like image 225
Roberto Tonini Avatar asked Aug 25 '17 09:08

Roberto Tonini


1 Answers

What you need Deep linking. To open your app on link click you need to add intent filer "android.intent.action.VIEW" 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="example.com"
                android:pathPrefix="/api/v1/view"
                android:scheme="http" />
        </intent-filter>

Once you build a link with same signature as mentioned in manifest The android system will add your app in chooser to open link in your app and you will get the data in "getIntent().getData()" in respective Activity.

If app is not installed the link will itself open in browser.Then handle it on browser .

To send intent from browser you need to follow same schema as manifest.

"intent://example.com/api/v1/view#Intent;scheme=http;package=com.app;category=android.intent.category.BROWSABLE;component=com.app.yourActivityname;action=android.intent.action.VIEW;end
like image 77
ADM Avatar answered Oct 06 '22 01:10

ADM