instant apps_Android Instant Apps 101:它们是什么以及它们如何工作
instant apps
by Tomislav Smrečki
通过TomislavSmrečki
Android Instant Apps are a cool new way to consume native apps without prior installation. Only parts of the app are downloaded and launched, giving the users a native look and feel in a couple of seconds.
Android Instant Apps是无需预先安装即可使用本机应用程序的一种很酷的新方法。 仅下载并启动了该应用程序的一部分,从而在几秒钟内为用户提供了本机外观。
它们如何工作? (How do they work?)
First of all, don’t confuse them with Progressive Web Apps where a launcher icon opens a web app via the Chrome browser. An Instant app will actually be installed on your phone, but without the need to search for it on the Play Store.
首先,不要将它们与渐进式Web应用程序混淆,在该应用程序中,启动器图标会通过Chrome浏览器打开网络应用程序。 Instant应用程序实际上将安装在您的手机上,但无需在Play商店中进行搜索。
Web URLs will trigger the Google Play Store on your phone and fetch only the part of the app that is associated with the requested URL. The rest of the app is not downloaded. This way users can quickly enjoy the native experience of your Android application.
网络URL将触发手机上的Google Play商店,并且仅提取与请求的URL关联的应用程序部分。 该应用程序的其余部分未下载。 这样,用户可以快速享受Android应用程序的本机体验。
背景是什么? (What’s the background?)
Well, you need to divide your Android project into a couple of modules. One of them is a base module with the essential code which is used in all other modules (API connection, database, shared preferences etc.). The other, feature modules, contain specific functionalities and activities which can be accessed via associated URLs.
好吧,您需要将Android项目划分为几个模块。 其中之一是具有必要代码的基本模块,该基本代码可在所有其他模块(API连接,数据库,共享首选项等)中使用。 其他功能模块包含可以通过关联的URL访问的特定功能和活动。
Let’s say you have a web app with a list of products and a single page of the product. For example, you can link https://example.domain/products to launch the ProductsListActivity and https://example.domain/products/12 to launch the ProductActivity.
假设您有一个Web应用程序,其中包含产品列表和产品的单个页面。 例如,您可以链接https://example.domain/products以启动ProductsListActivity和https://example.domain/products/12以启动ProductActivity。
To make them accessible as instant app activities, they need to be packed into individual feature modules and they need to have associated App Links defined in their module manifests. We will call them Product and Product list modules.
为了使它们可以作为即时应用程序活动进行访问,需要将它们打包到各个功能模块中,并且需要在其模块清单中定义关联的应用程序链接。 我们将它们称为“产品”和“产品列表”模块。
Now, when a user tries to open https://example.domain/products/12, both Product and Base modules will start to download and the ProductActivity will be launched.
现在,当用户尝试打开https://example.domain/products/12时 , Product和Base模块都将开始下载,并且ProductActivity将启动。
什么是应用链接,如何定义? (What are app links and how are they defined?)
You’ve probably heard of deep links. They are defined in the app manifest, and they will be registered to the OS. When a user tries to open such a link, the OS will ask the user to choose between opening the link in a web browser or in your app. However, this is not enough for Instant apps, you need to go one step further — App Links. You need to include the autoVerify=”true” property.
您可能听说过深层链接。 它们在应用清单中定义,并且将被注册到操作系统。 当用户尝试打开此类链接时,操作系统将要求用户在打开Web浏览器或应用程序中的链接之间进行选择。 但是,这对于Instant应用程序来说还不够,您需要再走一步-App Links 。 您需要包括autoVerify =“ true”属性。
<activity android:name=".ProductActivity"> <intent-filter android:autoVerify="true" android:order="100">
<action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="example.domain" android:pathPrefix="/products" /> <data android:scheme="https"/>
</intent-filter> </activity>
Your app will verify if the links you specified are really associated with your domain. For this, you need to include the assetlinks.json file into the following folder of your domain root:
您的应用将验证您指定的链接是否确实与您的域相关联。 为此,您需要将assetlinks.json文件包含到域根目录的以下文件夹中:
https://example.domain/.well-known/assetlinks.json.
https://example.domain/.well-known/assetlinks.json。
Also, notice the android:order=”100″ property. This is actually a priority in this case. If you have a product list and a product single that correspond to the same path (/products and /products/10), the product single activity will be launched if there’s an id after the /products path. If not, then the product list activity is launched.
另外,请注意android:order =“ 100”属性。 在这种情况下,这实际上是优先事项。 如果您有一个与相同路径(/ products和/ products / 10)相对应的产品列表和一个产品单,则在/ products路径后面有一个id时,将启动产品单活动。 如果不是,则启动产品列表活动。
It is very important to define this. If there are two activities that correspond to the same path, the Play Store won’t know which part of the app should be fetched.
定义这一点非常重要。 如果有两个活动对应同一路径,则Play商店将不知道应提取应用的哪一部分。
将您的应用与您的域相关联 (Associate your app with your domain)
The assetlinks.json will need to contain your SHA256 keystore hashes. The relation field is set to the default value below, and the target object needs to be filled with app specific data and your SHA256 hash of the keystore.
assetlinks.json将需要包含SHA256密钥库哈希 。 关系字段设置为下面的默认值,并且目标对象需要使用应用程序特定的数据和密钥库的SHA256哈希填充。
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.example.app", "sha256_cert_fingerprints":["00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"] } }]
When autoVerify=true does its magic, all associated App Links will directly launch your app. If you don’t have the app installed, the instant app will be downloaded instead.
当autoVerify = true发挥作用时,所有关联的应用程序链接将直接启动您的应用程序。 如果您尚未安装该应用,则将立即下载该即时应用。
Here’s an example of a demo app we did recently. When clicked on the associated link, a screen like this opens and offers to use the instant app instead. Note how quickly the app is opened, and on Oreo it’s even faster.
这是我们最近进行的演示应用程序的示例。 当单击关联的链接时,将打开一个类似这样的屏幕,并提示您使用即时应用程序。 请注意,该应用的打开速度有多快,在Oreo上则更快。
如何定义Android Instant模块? (How to Define Android Instant Modules?)
For an instant app, your project will consist of at least three different modules. You need to use Android Studio 3.0 for this. If you’re creating your app from scratch, there’s an option to enable the Instant app support for your project.
对于即时应用程序,您的项目将至少包含三个不同的模块。 您需要为此使用Android Studio 3.0。 如果您是从头开始创建应用程序,则可以选择为项目启用即时应用程序支持。
All of the following modules will be initialised automatically. If you’re modifying an older app, you’ll need to break the old app module into a single base module and a couple of feature modules. Also, you’ll need to create an App and an Instant app module, which you will use to build both regular and instant app APKs.
以下所有模块将自动初始化。 如果要修改较旧的应用程序,则需要将旧的应用程序模块拆分为一个基本模块和几个功能模块。 另外,您将需要创建一个应用程序和一个即时应用程序模块,用于构建常规和即时应用程序APK。
App Module
应用模块
First, you have to create an app module which defines the dependencies for all other modules (base + feature modules). In the build.gradle file of this module, you will need to define the following:
首先,您必须创建一个应用程序模块,该模块定义所有其他模块(基本+功能模块)的依赖关系。 在此模块的build.gradle文件中,您将需要定义以下内容:
apply plugin: 'com.android.application' ...
dependencies { implementation project(':product') implementation project(':productlist') implementation project(':base') }
Base Module
基本模块
In this module, you will define the following dependency statements. Also, make sure that the ‘com.android.feature’ plugin is applied here.
在本模块中,您将定义以下依赖项语句。 另外,请确保在此处应用了“ com.android.feature”插件。
apply plugin: 'com.android.feature' android { baseFeature true ... }
dependencies { api 'com.android.support:appcompat-v7:26.0.1' api 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.google.firebase:firebase-appindexing:11.0.4' application project(':app') feature project(':product') feature project(':productlist') }
Note that here, the compile statements become API statements for the regular dependencies we used before. The application project and feature projects are defined separately.
请注意,这里的compile语句成为我们之前使用的常规依赖项的API语句。 应用程序项目和功能项目是分别定义的。
Feature Module
功能模块
This module will have the following setting, also with the com.android.feature plugin applied.
该模块将具有以下设置,并且已应用com.android.feature插件。
apply plugin: 'com.android.feature' ... dependencies { implementation project(':base') ... }
You need to state which module is your base module and include it with the implementation project statement. Next, you can include the dependencies which are required only for this specific module. For example, if you’re using an animation library which is not used in any of the other modules.
您需要声明哪个模块是您的基本模块,并将其包含在实施项目语句中。 接下来,您可以包括仅此特定模块所需的依赖项。 例如,如果您使用的动画库在其他任何模块中均未使用。
Instant App Module
即时应用模块
Finally, now there’s a com.android.instantapp plugin to be included in the build.gradle file for the instantapp module.
最后,现在有一个com.android.instantapp插件包含在Instantapp模块的build.gradle文件中。
apply plugin: 'com.android.instantapp' dependencies { implementation project(':product') implementation project(':productlist') implementation project(':base') }
In this module, we will define which modules will be built as instant apps. The result of the instantapp module build is a zip file with the instant app APKs which you can upload separately to Google Play Store in the Android Instant Apps release manager. These APKs are handled similarly as the regular ones, they have their own rollout history and versioning.
在此模块中,我们将定义将哪些模块构建为即时应用程序。 Instantapp模块构建的结果是一个包含即时应用APK的zip文件,您可以在Android Instant Apps版本管理器中分别将其上传到Google Play商店。 这些APK的处理方式与常规APK类似,它们具有自己的推出历史记录和版本控制。
That’s it! It’s fairly simple to start developing Android Instant Apps. But, there’s always a but!
而已! 开始开发Android Instant Apps非常简单。 但是,总会有一个!
Android Instant Apps面临哪些挑战? (What were the Android Instant Apps’ challenges?)
First of all, the Instant Apps are not enabled by default for now. If you want to try it, you need to check your phone settings under Google account and enable the Instant Apps setting.
首先,默认情况下,暂时不启用Instant Apps。 如果要尝试,则需要检查Google帐户下的手机设置并启用“即时应用”设置。
Next, we found that it’s extremely important to specify app links data in the following format:
接下来,我们发现以以下格式指定应用链接数据非常重要:
<intent-filter android:autoVerify="true"> ... <data android:scheme="http" android:host="example.domain" android:pathPrefix="/products" /> <data android:scheme="https"/> </intent-filter>
Both http and https schemes need to be defined as shown in this code snippet. Any other way would cause a link verification failure and the app wouldn’t be linked properly.
如下面的代码片段所示,必须定义http和https方案。 任何其他方式都会导致链接验证失败,并且应用程序无法正确链接。
Also, there is a recommendation to include the following code snippet into one of the activities in your app manifest. This annotates which activity should be launched in case the Instant app is launched from the Settings or a system launcher.
另外,建议您在应用清单中的活动之一中包含以下代码段。 这可以注释在从“设置”或系统启动器启动Instant应用程序的情况下应启动的活动。
<meta-data android:name="default-url" android:value="https://example.domain" />
The official documentation states that the Google Search would offer Instant app annotation by default (small thunder icon), but we had problems with it. For our demo app, this was not the case. Google Search results didn’t annotate our demo links as Instant apps and the links led to the web page. Only if we tried to open the associated link from another app, like Gmail, the whole instant app process was triggered and the instant app was launched. Have you encountered any similar problems?
官方文档指出,默认情况下,Google搜索会提供即时应用注释(小小的雷声图标),但是我们遇到了问题。 对于我们的演示应用程序,情况并非如此。 Google搜索结果没有将我们的演示链接注释为Instant apps,并且这些链接指向了网页。 仅当我们尝试打开其他应用程序(例如Gmail)的关联链接时,整个即时应用程序流程才会被触发并启动即时应用程序。 您是否遇到过类似的问题?
结论 (Conclusion)
When first announced two years ago, I was very enthusiastic about Android Instant Apps. They respond to the problem of users having to search for the apps on the Store and wait till they’re downloaded to start using them. Web apps are much more accessible in that regard and the ease of discovery is much better.
两年前首次发布时,我对Android Instant Apps非常热衷。 他们回应了用户不得不在商店中搜索应用程序并等到下载后才能开始使用它们的问题。 在这方面,Web应用程序更易于访问,发现的便利性更好。
Instant apps come really close to filling this gap between web and native mobile apps. They already act very well and I think that they will become more popular with time. The main problems we encountered was a rather small community and the lack of proper documentation, but the situation on that matter is also getting better.
即时应用程序确实接近填补了网络和本机移动应用程序之间的空白。 他们已经表现得很好,我认为他们会随着时间的推移变得越来越受欢迎。 我们遇到的主要问题是一个相对较小的社区和缺乏适当的文档,但是在此问题上的情况也越来越好。
We would love to hear from you if you’ve tried using them or had any challenges implementing them!
如果您尝试使用它们或在实现它们时遇到任何挑战,我们很乐意听取您的意见!
Originally published at www.bornfight.com.
最初在www.bornfight.com上发布。
翻译自: https://www.freecodecamp.org/news/android-instant-apps-101-what-they-are-and-how-they-work-8b039165ed24/
instant apps
相关文章:

数据库分享一: MySQL的Innodb缓存相关优化
无论是对于哪一种数据库来说,缓存技术都是提高数据库性能的关键技术,物理磁盘的访问速度永 远都会与内存的访问速度永远都不是一个数量级的。通过缓存技术无论是在读还是写方面都可以大大提 高数据库整体性能。Innodb_buffer_pool_size 的合理设置Innodb…

用过美德乐吸奶器的宝妈们感觉比国产吸奶器怎么样啊?
药效好不好,看疗效就知道。吸奶器好不好看评价就知道。我们来看看美德乐吸奶器 天猫旗舰店 : http://medela.wang 的宝妈们的评价如可 拔奶神器,绝对好过贝亲!最初一次七八十,后来一百多,现在可以翻个倍。结合宝宝吮吸…

小程序地图多个 circles 使用demo
效果图: 代码: var that; const app getApp() const util require("../../utils/util.js") const data require("../../utils/map.js") Page({data: {pageShow: false,scale: 15,obj: {},longitude: 116.34665554470486,latitud…

编写文档_如何通过编写优质文档来使自己的未来快乐
编写文档by Gabriele Cimato加布里埃莱西马托(Gabriele Cimato) 如何通过编写优质文档来使自己的未来快乐 (How to make your future self happy by writing good docs) 或者,在清除旧代码库时如何减少痛苦 (Or how to be less miserable when dusting off an old …

(转载)人人都会OSGI--实例讲解OSGI开发
http://longdick.iteye.com/blog/457310转载于:https://www.cnblogs.com/eecs2016/articles/7422310.html

小程序json字符串转 json对象 { name :你好} 转成 { name :你好}
解决后端接口返回 var obj "{ name :"你好"}" 类似这样的数据,对象或者数组外面包了一层引号, 把这种数据转成 var obj { name :"你好"}; 直接上代码: // pages/test/test.js Page({jsonStrToJ…

每天写的叫工作日志,每周写的总结叫周报,每月写的叫月报
有些时候,老板会突发让您求每天都要写工作周报,什么项目什么任务,完成情况,完成花费的时间等,然后汇总部门周报;也不是写不出,只是不知道有时候重复做一个项目,到底每天有什么好写&a…

为什么分散刷新没有死时间_分散项目为何失败(以及如何处理)
为什么分散刷新没有死时间The most exciting thing about working in the decentralized economy is the fact that no one has any idea as to where it’ll all end up!在去中心decentralized economy工作最令人振奋的事情是,没有人知道最终的结果! T…

.NET Core 常用加密和Hash工具NETCore.Encrypt
前言 在日常开发过程中,不可避免的涉及到数据加密解密(Hash)操作,所以就有想法开发通用工具,NETCore.Encrypt就诞生了。目前NETCore.Encrypt只支持.NET Core ,工具包含了AES,DES,RSA加密解密,MD5࿰…

url 通配符解析成参数
需求:url 参数是通配符,需要把通配符解析成参数并且拼接到 url 中 例如:https://xxx.cn/index.html$a1$b2; 解析成 https://xxx.cn/index.html?a1&b2; 时间关系,直接上代码,有时间再补上注释 下面是小程序页…

性能测试分享:系统架构
性能测试分享:系统架构 转载于:https://www.cnblogs.com/poptest/p/4904584.html

graphql是什么_为什么GraphQL是避免技术债务的关键
graphql是什么GraphQL (not to be confused with GraphDB or Open Graph or even an actual graph) is a remarkably creative solution to a relatively common problem: How do you enable front end developers to access backend data in exactly the way they need it?Gr…

JS如何判断json是否为空
1、判断json是否为空 jQuery.isEmptyObject(); 2、遍历json function getHsonLength(json{var jsonLength0;for (var i in json){jsonLength;}return jsonLength;}转载于:https://www.cnblogs.com/donaldworld/p/7423811.html

微软算法100题11 求二叉树中两节点之间的最大距离
第11 题求二叉树中节点的最大距离...如果我们把二叉树看成一个图,父子节点之间的连线看成是双向的,我们姑且定义"距离"为两节点之间边的个数。写一个程序,求一棵二叉树中相距最远的两个节点之间的距离 思路: 一棵树中节点的最大距…

小程序订阅消息 订阅消息开发
微信小程序交流QQ群: 173683895 173683866 526474645 。 群内打广告或者脏话一律飞机票 订阅消息 当用户勾选了订阅面板中的“总是保持以上选择,不再询问”时,模板消息会被添加到用户的小程序设置页,通过 wx.getSetting…

meetup_如何使用标准库和Node.js构建Meetup Slack机器人
meetupby Janeth Ledezma简妮丝莱德兹玛(Janeth Ledezma) 如何使用标准库和Node.js构建Meetup Slack机器人 (How to build a Meetup Slack bot with Standard Library and Node.js) In this guide, you will learn how to set up a Slack application that will display infor…

.NET使用OpenSSL生成的pem密钥文件[1024位]
using System; using System.Text; using System.Security.Cryptography; using System.Web; using System.IO;namespace Thinhunan.Cnblogs.Com.RSAUtility {public class PemConverter{/// <summary>/// 将pem格式公钥转换为RSAParameters/// </summary>/// <…

[2014百度之星资格赛]
第一个问题: Energy Conversion Problem Description魔法师百小度也有遇到难题的时候——如今。百小度正在一个古老的石门面前,石门上有一段古老的魔法文字,读懂这样的魔法文字须要耗费大量的能量和大量的脑力。过了许久。百小度最终读懂魔法…

视频录制,压缩实现源码
实现代码: <!DOCTYPE html> <html><head><meta charset"utf-8"><title></title><meta name"viewport" content"widthdevice-width, initial-scale1.0"><!-- <script src"./js…

alexa技能个数_如何在您的技能中使用Alexa演示语言
alexa技能个数by Garrett Vargas通过Garrett Vargas 如何在您的技能中使用Alexa演示语言 (How to use Alexa Presentation Language in your skill) Amazon recently released the Alexa Presentation Language (APL). APL provides a richer display for multimodal skills. …

HTML与XML总结
阅览《孙欣HTML》和《刘炜XML》过了一段时间,在这里学到的内容用思维导图来概括。HTML与XML都是标记语言。 同样点: HTML文档与XML文档有类似的结构。前者是(head和body)后者是(声明和主体),大致…

ant PageHeaderWrapper 返回上一页
PageHeaderWrapper 返回上一页实现代码: <PageHeaderWrappertitle{false}content{<a onClick{() > router.goBack()}><Icon type"left" />返回</a>}breadcrumb{{routes: [{ path: /, breadcrumbName: 首页 },{ path: /pay_orde…

ruby 新建对象_Ruby面向对象编程的简介
ruby 新建对象by Saul Costa由Saul Costa Object-oriented programming (OOP) is a programming paradigm organized around objects. At a high level, OOP is all about being able to structure code so that its functionality can be shared throughout the application.…

ASP.NET导出文件FileResult的使用
本文给大家讲一下ASP.NET MVC中如何使用FileResult来导出文件,首先网上相关例子有很多大神都有讲,我在这只是稍微说一点不同——为什么我的导出没有反应呢? 这个问题,我找了半天也没有找到,最后是在一个网友的评论中体…

【AHOI 2016初中组】 自行车比赛 - 贪心
题目描述 小雪非常关注自行车比赛,尤其是环滨湖自行车赛。一年一度的环滨湖自行车赛,需要选手们连续比赛数日,最终按照累计得分决出冠军。今年一共有 N 位参赛选手。每一天的比赛总会决出当日的排名,第一名的选手会获得 N 点得分&…

【Ant Design Pro 三】样式动态绑定 react样式绑定
第一步,创建样式文件,在页面目录下根据自己习惯创建一个less文件,用来写样式类 第二部,引用该文件 import styles from ./details.less; //details.less 代码: .menu {width: 95%; } .navigation-menu{width: 90%; …

react hooks使用_如何使用React和Hooks检测外部点击
react hooks使用by Andrei Cacio通过安德烈卡西奥(Andrei Cacio) 如何使用React和Hooks检测外部点击 (How to detect an outside click with React and Hooks) “外部点击”是什么意思? (What does “Outside Click” mean?) You can think of it as the “anti-b…

正则表达式(1)
正则表达式的概念 正则表达式是一个字符串,使用单个字符串来描述、用来定义匹配规则,匹配一系列符合某个句法规则的字符串。在开发中,正则表达式通常被用来检索、替换那些符合某个规则的文本。 正则表达式的匹配规则 字符类:[abc]…

Android 曲线动画animation,类似加入购物车动画
按照惯例先放效果图:图中小球做抛物线运动 资源图片 1.首先布局文件activity_main.xml,布局很简单,就一个测试按钮 1 <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"2 xmlns:tools"http:…

小程序音频播放报10001 解决方案 errCode:10001, errMsg:errCode:602,err:error,not found param
音频播放有两种方式: 第一种: innerAudioContext.src audioSrc;innerAudioContext.play(); 第二种: innerAudioContext.autoplay true;innerAudioContext.src audioSrc; 之前使用第一种,华为手机不能正常播放,…