如何访问参数并将参数传递给Android Instant App的模块 [英] How to access and pass parameters to the modules of an Android Instant App

查看:143
本文介绍了如何访问参数并将参数传递给Android Instant App的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用常规安装的应用程序,可以使用深层链接技术,不仅可以从URL打开特定的应用程序,还可以将其重定向到特定的部分/功能,例如特定的Facebook帖子或地图上的特定坐标.

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.

自从我读完Instant Apps以来,由于链接已经指向要下载和运行的特定模块,因此将无法实现,那么如何不仅可以访问所述模块,还可以向其传递一些参数?

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?

例如:

这是将从中下载我的地图应用程序的仅查看模块的链接:" www.myinstantappexample.com/onlyviewmap "

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

如果我希望它指向一组特定的坐标,将如何组成链接? 会是这样吗:" www.myinstantappexample.com/onlyviewmap/?x=0.000&y=0.000 "?

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.

推荐答案

即时应用和深度链接

即时应用程序依靠应用程序链接可以正常工作,而应用链接只是深层链接的一种类型.因此,对于Instant Apps来说,深层链接仍然是可能的,实际上,对于它们的功能绝对至关重要.但是, 不支持URI方案深层链接(在Android应用中仍然很普遍).

Instant Apps and Deep Linking

Instant Apps rely on App Links to work, and App Links are just one type of deep link. So deep linking is still possible for Instant Apps, and is in fact absolutely critical to how they function. However, URI scheme deep linking (which is still very prevalent in Android apps) is not supported.

常规应用程序和即时应用程序之间的区别在于,设备仅会响应用户单击的应用程序链接来加载单个活动,而不需要通过Play商店下载完整的程序包.对于用户而言,这是一种更加无缝的体验,但是基础技术的工作方式相同.

The difference between a regular app and an Instant App is that the device will only load a single Activity in response to the App Link the user clicks, instead of needing to download the full package through the Play Store. It's a more seamless experience for the user, but the underlying technology works the same way.

如果用户单击启用了App Links的URL,例如http://www.myinstantappexample.com/onlyviewmap/?x=0.000&y=0.000,则在打开应用程序后,您将获得整个字符串.您必须自己解析xy变量,但是它们将对您可用.像这样:

If the user clicks an App Links-enabled URL like http://www.myinstantappexample.com/onlyviewmap/?x=0.000&y=0.000, you will get that entire string back inside the app after it opens. You'll have to parse out the x and y variables yourself, but they will be available to you. Something like this:

Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
    String uri = this.getIntent().getDataString();
    Log.i("MyApp", "Deep link clicked " + uri);
}

您只需要操纵uri值即可找到所需的内容.

You'll just need to manipulate the uri value to find what you need.

或者,您可以使用 Branch.io (完整说明:我在分支团队中)来为您的链接提供动力.我们具有对Instant Apps的全面支持,这使您可以工作具有更友好的数据格式.我们让您创建这样的链接,以控制行为的每个部分:

Alternatively, you can use Branch.io (full disclosure: I'm on the Branch team) to power your links. We have full support for Instant Apps, and this allows you to work with a much more friendly data format. We let you create links like this, to control every part of the behavior:

branch.link({
    tags: [ 'tag1', 'tag2' ],
    channel: 'facebook',
    feature: 'dashboard',
    stage: 'new user',
    data: {
        x: '0.000',
        y: '0.000',
        '$desktop_url': 'http://myappwebsite.com',
        '$ios_url': 'http://myappwebsite.com/ios',
        '$ipad_url': 'http://myappwebsite.com/ipad',
        '$android_url': 'http://myappwebsite.com/android',
        '$og_app_id': '12345',
        '$og_title': 'My App',
        '$og_description': 'My app\'s description.',
        '$og_image_url': 'http://myappwebsite.com/image.png'
    }
}, function(err, link) {
    console.log(err, link);
});

作为回报,您获得一个类似http://myappname.app.link/iDdkwZR5hx的URL,然后在单击链接之后在应用程序内部,您将获得如下所示的内容:

In return you get a URL like http://myappname.app.link/iDdkwZR5hx, and then inside the app after the link is clicked, you'll get something that looks like this:

{
    tags: [ 'tag1', 'tag2' ],
    channel: 'facebook',
    feature: 'dashboard',
    stage: 'new user',
    data: {
        x: '0.000',
        y: '0.000'
    }
}

这篇关于如何访问参数并将参数传递给Android Instant App的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆