How to access and pass parameters to the modules of an Android Instant App

user8037871 picture user8037871 · May 19, 2017 · Viewed 19.4k times · Source

With normal installed apps it's possible to use the technique of Deep Linking in order to not only open a specific application from an URL but also to redirect it to a specific section/function such as a specific Facebook post or specific coordinates on a map.

Since I've read that with Instant Apps this won't be possible because links already point to the specific module to download and run, how would it be possible to access not only the said module but also pass it some parameters?

For example:

This is the link from which the view-only module of my map application will be downloaded: "www.myinstantappexample.com/onlyviewmap"

If I want it to point to a specific set of coordinates how would the link be composed? Will it be like this: "www.myinstantappexample.com/onlyviewmap/?x=0.000&y=0.000" ?

From what I've been able to find google doesn't cover this aspect and I really can't wrap my head around it.

Answer

AdamK picture AdamK · May 20, 2017

If I want it to point to a specific set of coordinates how would the link be composed?

It's up to you how to include any additional info in the URL. It could be via URL parameters or in the path itself. Eg.

https://www.myinstantappexample.com/location/2/user/5 https://www.myinstantappexample.com/onlyviewmap/?x=1.2&y=3.4

You then parse the URL in the receiving Activity. The Uri class includes a number of helper methods such as getQueryParameter() and getPathSegments() to make this easier.

For example, to parse this URL:

https://www.myinstantappexample.com/onlyviewmap/?x=1.2&y=3.4

You would do something like this in your Activity:

Uri uri = getIntent().getData();
String x;
String y;
if (uri != null) {
  x = uri.getQueryParameter("x"); // x = "1.2"
  y = uri.getQueryParameter("y"); // y = "3.4"
}
if (x != null && y != null) {
  // do something interesting with x and y
}