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

前端 未结 3 2166
-上瘾入骨i
-上瘾入骨i 2020-12-17 15:02

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

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 15:15

    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
    }
    

提交回复
热议问题