Launch android application from Browser using Uri of Launch Intent

Ever wondered, How do we launch application from Browser? For applications already installed in your device, if you visit eCommerce like amazon, ebay or entertainment website they will show you link to navigate to application or continue with browser.

If we launch app at some later stage, they will resume same display category or video resumed from last running time. We will check it with sample application.

After creating and installing sample application in your device, Click following link. Click here to launch sample app It will launch sample application.

Create a new application with package name “com.androidsrc.openappfromurl”. Activity layout will have a textview which will show text retrieved from values passed from Uri.

Edit your application manifest file, add a new IntentFilter to your activity with action as “com.androidsrc.launchfrombrowser” and define category to be default and browseable. Final AndroidManifest.xml will be as below.

Create /res/layout/activity_main.xml as below

Finally, We will retrieve intent that started activity in onCreate(). If intent action matches to that of what we defined in browser link, we will retrieve extra values passed from it. We can use these values to redirect/show view as required. MainActivity.java will be as below.

Let’s move over to browser. Now we will see how to create intent Uri to define in html tag that launched our application.

Let’s understand how to create Uri. Define Intent in your usual way. Add action and category for intent, add extras if you want.

To convert above Intent to Uri, use toUri() api with flag passed as Intent.URI_INTENT_SCHEME. For above defined Intent, you will get Uri as intent:#Intent;action=com.androidsrc.launchfrombrowser;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;S.msg_from_browser=Launched%20from%20Browser;end

If you try logging above intent, you will get same output.

At Browser side, it will look as below

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *