Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...