I am looking a work around to trigger my Android App with a website hyperlink (from Google Chrome) along with some params as well.
Asked
Active
Viewed 767 times
-1
-
That is generally called "deep link", you should read this article: https://developer.android.com/training/app-indexing/deep-linking.html – mdelolmo Aug 07 '14 at 14:45
1 Answers
1
You need to add an <intent-filter>
in your AndroidManifest.xml
<intent-filter>
<data android:scheme="scheme" android:host="host.com" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Link to it in html code like this:
<a href="scheme://host.com/parameter1/parameter2">
When the link is clicked, your app will be launched. You can get the params in you app like this:
// From link: scheme://host.com/foo/bar
Uri myData = getIntent().getData();
String scheme = data.getScheme(); // "scheme"
String host = data.getHost(); // "host.com"
List<String> parameters = data.getPathSegments();
String parameter1 = params.get(0); // "foo"
String parameter2 = params.get(1); // "bar"
Note that you can use http
as your scheme to handle ordinary links to a particular host.
Check out this question for additional info, and look at the docs page on intent-filter.
Hope this helps!