Launch custom android application from android browser

AndroidAndroid IntentIntentfilter

Android Problem Overview


Can anybody please guide me regarding how to launch my android application from the android browser?

Android Solutions


Solution 1 - Android

Use an http://developer.android.com/guide/topics/manifest/intent-filter-element.html">`<intent-filter>`</a> with a http://developer.android.com/guide/topics/manifest/data-element.html">`<data>`</a> element. For example, to handle all links to twitter.com, you'd put this inside your <activity> in your AndroidManifest.xml:

<intent-filter>
    <data android:scheme="http" android:host="twitter.com"/>
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.

Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:

<intent-filter>
    <data android:scheme="my.special.scheme" />
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

Then, in your web app you can put links like:

<a href="my.special.scheme://other/parameters/here">

And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.


Edit: To answer your question, you can use getIntent().getData() which returns a http://d.android.com/reference/android/net/Uri.html">`Uri`</a> object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234:

Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"

You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments in the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.

Solution 2 - Android

All above answers didn't work for me with CHROME as of 28 Jan 2014

my App launched properly from http://example.com/someresource/ links from apps like hangouts, gmail etc but not from within chrome browser.

to solve this, so that it launches properly from CHROME you have to set intent filter like this

<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="/someresource/"
        android:scheme="http" />
    <data
        android:host="www.example.com"
        android:pathPrefix="/someresource/"
        android:scheme="http" />
</intent-filter>

note the pathPrefix element

your app will now appear inside activity picker whenever user requests http://example.com/someresource/ pattern from chrome browser by clicking a link from google search results or any other website

Solution 3 - Android

Please see my comment here: https://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app/3472228#3472228

We strongly discourage people from using their own schemes, unless they are defining a new world-wide internet scheme.

Solution 4 - Android

In my case I had to set two categories for the <intent-filter> and then it worked:

<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

Solution 5 - Android

For example, You have next things:

>A link to open your app: http://example.com

>The package name of your app: com.example.mypackage

Then you need to do next:

  1. Add an intent filter to your Activity (Can be any activity you want. For more info check the https://developers.google.com/app-indexing/android/app">documentation</a>;).

    <activity
         android:name=".MainActivity">
    
         <intent-filter android:label="@string/filter_title_view_app_from_web">
             <action android:name="android.intent.action.VIEW" />
             <category android:name="android.intent.category.DEFAULT" />
             <category android:name="android.intent.category.BROWSABLE" />
             <!-- Accepts URIs that begin with "http://example.com" -->
     		
             <data
                 android:host="example.com"
                 android:scheme="http" />
         </intent-filter>
    
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
    
     </activity> 
    
  2. Create a HTML file to test the link or use https://developers.google.com/app-indexing/webmasters/test">this methods.

    Open your Activity directly (just open your Activity, without a choosing dialog).

    http://example.com">Open this link with browser or your programm (by choosing dialog).

  3. Use Mobile Chrome to test

  4. That's it.

And its not necessary to publish app in market to test deep linking =)

Also, for more information, check https://developers.google.com/app-indexing/android/app">documentation</a> and useful http://www.slideshare.net/ravalketan/android-deep-linking">presentation</a>;.

Solution 6 - Android

There should also be <category android:name="android.intent.category.BROWSABLE"/> added to the intent filter to make the activity recognized properly from the link.

Solution 7 - Android

The following link gives information on launching the app (if installed) directly from browser. Otherwise it directly opens up the app in play store so that user can seamlessly download.

https://developer.chrome.com/multidevice/android/intents

Solution 8 - Android

Please note if your icon is disappear from android launcher when you implement this feature, than you have to split intent-filter.

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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:scheme="your-own-uri" />
        </intent-filter>
    </activity>

Solution 9 - Android

Yeah, Chrome searches instead of looking for scheme. If you want to launch your App through URI scheme, use this cool utility App on the Play store. It saved my day :) https://play.google.com/store/apps/details?id=com.naosim.urlschemesender

Solution 10 - Android

Xamarin port of Felix's answer

In your MainActivity, add this (docs: Android.App.IntentFilterAttribute Class):

....
[IntentFilter(new[] { 
	Intent.ActionView }, 
	Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
	DataScheme = "my.special.scheme")
]
public class MainActivity : Activity
{
    ....

Xamarin will add following in the AndroidManifest.xml for you:

<activity
	android:label="Something"
	android:screenOrientation="portrait"
	android:theme="@style/MyTheme"
	android:name="blah.MainActivity">
	<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:scheme="my.special.scheme" />
	</intent-filter>
</activity>

And in order to get params (I tested in OnCreate of MainActivity):

var data = Intent.Data;
if (data != null)
{
    var scheme = data.Scheme;
    var host = data.Host;
    var args = data.PathSegments;

    if (args.Count > 0)
    {
        var first = args[0];
        var second = args[1];
        ...
    }
}

As far as I know, above can be added in any activity, not only MainActivity

Notes:

  1. When user click on the link, Android OS relaunch your app (kill prev instance, if any, and run new one), means the OnCreate event of app's MainLauncher Activity will be fired again.
  2. With this link: <a href="my.special.scheme://host/arg1/arg2">, in above last code snippet values will be:
scheme: my.special.scheme
host: host
args: ["arg1", "arg2"]
first: arg1
second: arg2

Update: if android creates new instance of your app, you should add android:launchMode="singleTask" too.

Solution 11 - Android

Felix's approach to handling deep links is the typical approach to handling deep links. I would also suggest checking out this library to handle the routing and parsing of your deep links:

https://github.com/airbnb/DeepLinkDispatch

You can use annotations to register your Activity for a particular deep link URI, and it will extract out the parameters for you without having to do the usual rigmarole of getting the path segments, matching it, etc. You could simply annotate and activity like this:

@DeepLink("somePath/{someParameter1}/{someParameter2}")
public class MainActivity extends Activity {
   ...
}

Solution 12 - Android

Hey I got the solution. I did not set the category as "Default". Also I was using the Main activity for the intent Data. Now i am using a different activity for the intent data. Thanks for the help. :)

Solution 13 - Android

You need to add a pseudo-hostname to the CALLBACK_URL 'app://' doesn't make sense as a URL and cannot be parsed.

Solution 14 - Android

example.php:

<?php
if(!isset($_GET['app_link'])){  ?>   
	<iframe src="example.php?app_link=YourApp://blabla" style="display:none;" scrolling="no" frameborder="0"></iframe>
	<iframe src="example.php?full_link=http://play.google.com/xyz" style="display:none;" scrolling="no" frameborder="0"></iframe>
	<?php 
}
else { ?>
	<script type="text/javascript">
	self.window.location		= '<?php echo $_GET['app_link'];?>';
	window.parent.location.href = '<?php echo $_GET['full_link'];?>';
	</script>
<?php 
}

Solution 15 - Android

Look @JRuns answer in here. The idea is to create html with your custom scheme and upload it somewhere. Then if you click on your custom link on your html-file, you will be redirected to your app. I used this article for android. But dont forget to set full name Name = "MyApp.Mobile.Droid.MainActivity" attribute to your target activity.

Solution 16 - Android

As of 15/06/2019

what I did is include all four possibilities to open url.

i.e, with http / https and 2 with www in prefix and 2 without www

and by using this my app launches automatically now without asking me to choose a browser and other option.

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="https" android:host="example.in" />
    <data android:scheme="https" android:host="www.example.in" />
    <data android:scheme="http" android:host="example.in" />
    <data android:scheme="http" android:host="www.example.in" />

</intent-filter>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionParimal ModiView Question on Stackoverflow
Solution 1 - AndroidFelixView Answer on Stackoverflow
Solution 2 - AndroidAndroidGeckoView Answer on Stackoverflow
Solution 3 - AndroidhackbodView Answer on Stackoverflow
Solution 4 - AndroidZakiView Answer on Stackoverflow
Solution 5 - AndroidDeniSHowView Answer on Stackoverflow
Solution 6 - AndroidgeorgijView Answer on Stackoverflow
Solution 7 - AndroidVarun BhatiaView Answer on Stackoverflow
Solution 8 - AndroidZoltanView Answer on Stackoverflow
Solution 9 - AndroidRRKView Answer on Stackoverflow
Solution 10 - AndroidMehdi DehghaniView Answer on Stackoverflow
Solution 11 - AndroidChristianView Answer on Stackoverflow
Solution 12 - AndroidParimal ModiView Answer on Stackoverflow
Solution 13 - AndroidPaul LindnerView Answer on Stackoverflow
Solution 14 - AndroidT.ToduaView Answer on Stackoverflow
Solution 15 - AndroidS. KoshelnykView Answer on Stackoverflow
Solution 16 - AndroidVicky SalunkheView Answer on Stackoverflow