android应用程序_您应该了解的有关Android即时应用程序的所有信息

android应用程序

本文的重点 (Takeaway From the Article)

In this article, you’re going to learn how to create instant apps for your Android users. Along with that, you’ll also learn how to prompt the user to install the full version of the app, a proper way of testing instant apps, how to use instant apps with URLs, and more. Read on to learn about them.

在本文中,您将学习如何为Android用户创建即时应用。 除此之外,您还将学习如何提示用户安装完整版应用程序,测试即时应用程序的正确方法,如何将即时应用程序与URL结合使用等等。 继续阅读以了解它们。

介绍 (Introduction)

Instant apps are a technology that provides the native experience of Android apps without explicit installation.

即时应用程序是一项无需显式安装即可提供Android应用程序本机体验的技术。

When your Android app has the instant-app feature, then users will see the “try now” button beside “install” on your app details screen in the Google Play store. By clicking on the “try now” button, a virtual app is installed.

当您的Android应用具有即时应用功能时,用户将在Google Play商店的应用详细信息屏幕上看到“安装”旁边的“立即尝试”按钮。 通过单击“立即尝试”按钮,将安装虚拟应用程序。

Only the modules that developers declare as an instant app in their manifest file will be downloaded at this moment. This allows users to experience the app briefly before installing the entire application. If your app size is large, this option will give a peek into the features of your app without actually downloading it.

此时,仅下载开发人员在其清单文件中声明为即时应用的模块。 这使用户可以在安装整个应用程序之前短暂地体验该应用程序。 如果您的应用程序很大,则此选项将使您无需实际下载即可浏览应用程序的功能。

注意事项 (Things to Keep in Mind)

Now we know what an instant app is and how it can be helpful to users and business owners. As many benefits as it provides, it also comes with some restrictions.

现在我们知道了即时应用程序是什么,以及它如何对用户和企业主有所帮助。 它提供的好处很多,但也有一些限制。

  1. Instant-app enabled app bundles can only use few app permissions, such as ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, ACCESS_NETWORK_STATE, CAMERA, INSTANT_APP_FOREGROUND_SERVICE [only in Android 8.0 (API level 26) and higher], INTERNET, READ_PHONE_NUMBER, RECORD_AUDIO, VIBRATE, and WAKE_LOCK.

    即时应用启用应用束只能使用少数的应用权限,如ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATIONACCESS_NETWORK_STATECAMERAINSTANT_APP_FOREGROUND_SERVICE [仅在的Android 8.0(API级26)和更高] INTERNETREAD_PHONE_NUMBERRECORD_AUDIOVIBRATEWAKE_LOCK

  2. By default, instant apps can’t interact with the installed app unless one of the following conditions are satisfied:

    默认情况下,除非满足以下条件之一,否则即时应用程序无法与已安装的应用程序进行交互:

    a.) At least one of the activities in the installed app should have the attribute

    a。)安装的应用程序中的至少一项活动应具有该属性

    android:visibleToInstantApps in its manifest file marked as true.

    清单文件中标记为true android:visibleToInstantApps

    b.)

    b。)

    The installed app contains a CATEGORY_BROWSABLE intent filter.

    已安装的应用包含CATEGORY_BROWSABLE意向过滤器。

  3. The instant-app feature is built on top of Android app bundles using a split APKs feature that was introduced in Android Lollipop. So developers need to change their app distribution to Android app bBundles from the traditional APK to work with instant apps.

    即时应用功能是使用Android Lollipop中引入的拆分APK功能在Android应用捆绑包的基础上构建的。 因此,开发人员需要将其应用分配从传统的APK更改为Android应用bBundles,以使用即时应用。

积分 (Integration)

Include Google Play Instant API in your app by adding the following line under the dependency node in the app-level build.gradle file.

通过在应用程序级别build.gradle文件的依赖项节点下添加以下行,将Google Play Instant API包含在您的应用程序中。

implementation "com.google.android.gms:play-services-instantapps:17.0.0"

If you’re using any previous instant-app plugins, you can remove them. The new instant API doesn’t need any plugins, and with this new API, you can use one code for both instant and full versions of the app.

如果您使用的是以前的即时应用插件,则可以将其删除。 新的Instant API不需要任何插件,并且使用此新API,您可以为该应用的即时版本和完整版本使用一个代码。

启用即时体验 (Enable the Instant Experience)

版本代码维护 (Version-code maintenance)

The version code of the instant experience of your app should be less than the actual version code of the app. This is because when users move from the instant app to the full-app installation, Google Play considers it as an app update. So the ascending order of the version code makes sense.

您应用的即时体验的版本代码应小于应用的实际版本代码。 这是因为当用户从即时应用程序迁移到完整应用程序安装时,Google Play会将其视为应用程序更新。 因此,版本代码的升序是有意义的。

Even if the users already installed the application, they experience instant apps through URLs, which you’ll see in a bit. But before that, you should be careful with version code — at any instance, the instant app should have less version code.

即使用户已经安装了应用程序,他们也会通过URL体验即时应用程序,您将很快看到它。 但是在此之前,您应该注意版本代码-在任何情况下,即时应用程序的版本代码都应该更少。

Google’s recommendation is to increase the version code of the installable APK by a large number, such as 1,000, to ensure there’s enough space for your instant-experience’s version number to increase.

Google的建议是大量增加可安装APK的版本代码(例如1,000),以确保有足够的空间来增加即时体验的版本号。

沙盒版本 (Sandbox version)

As I said, instant apps won’t install in the device. Instead, they’ll be operated from a sandbox storage. For this purpose, we need to include targetSandboxVersion attribute in the manifest file, as shown below:

正如我所说,即时应用程序不会安装在设备中。 相反,它们将从沙箱存储中进行操作。 为此,我们需要在清单文件中包含targetSandboxVersion属性,如下所示:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
...
android:targetSandboxVersion="2" ...>

在模块级别启用即时体验 (Enable instant-experience at the module level)

To make a module instant-app support, we just need to add the following line in the manifest file, as shown below. This is mandatory in the base module and in the modules that you intended to include in the instant-app experience.

为了使模块支持即时应用程序,我们只需要在清单文件中添加以下行,如下所示。 这在基本模块和您打算包含在即时应用程序体验中的模块中是必需的。

<manifest 
xmlns:dist="http://schemas.android.com/apk/distribution">
<dist:module dist:instant="true" .../>
...
</manifest>

具有即时应用程序的动态模块 (Dynamic modules with instant apps)

We can also use dynamic feature modules in instant apps. The easiest way to create a dynamic feature module that supports instant apps is to make use of the module templates from Android Studio.

我们还可以在即时应用程序中使用动态功能模块。 创建支持即时应用程序的动态功能模块的最简单方法是利用Android Studio中的模块模板。

To create an instant dynamic feature module, navigate as so:

要创建即时动态功能模块,请按以下方式导航:

File > New > New Module

文件>新建>新建模块

Then, a new window is opened with different templates related to different configurations. In the list, select the instant dynamic feature module option, and click next. After that, you can give a name to the module, and you can give apackage name as well.

然后,将打开一个新窗口,其中包含与不同配置相关的不同模板。 在列表中,选择 即时动态功能模块选项,然后单击下一步。 之后,您可以给模块命名,也可以给包命名。

URL映射 (URL Mapping)

What if you want to provide an instant-app experience when an URL is loaded into the mobile. It’s possible, but you should implement the following things to make it work:

如果要在将URL加载到手机中时提供即时应用体验,该怎么办。 有可能,但是您应该实施以下操作以使其起作用:

  1. First, you should add a second intent filter by setting autoVerify to true.

    首先,您应该通过将autoVerify设置为true来添加第二个意图过滤器。

    First, you should add a second intent filter by setting autoVerify to true.<intent-filter android:autoVerify=”true”>

    首先,您应该通过将autoVerify设置为true来添加第二个意图过滤器。 <intent-filter android: autoVerify =”true”>

  2. Then, add the following category and action flags under the above-created intent filter.

    然后,在上面创建的意图过滤器下面添加以下类别和操作标志。

    Then, add the following category and action flags under the above-created intent filter.<action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.BROWSABLE" /><category android:name="android.intent.category.DEFAULT" />

    然后,在上面创建的意图过滤器下面添加以下类别和操作标志。 <action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.BROWSABLE" /><category android:name="android.intent.category.DEFAULT" />

  3. Finally, we need to add the URL schemas, as shown below:

    最后,我们需要添加URL模式,如下所示:
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:host="example.com"/>
<data android:path="/instantapp/schedule"/>

We can also specify a default URL that’s used to launch the instant experience more easily, as shown below:

我们还可以指定一个默认URL,用于更轻松地启动即时体验,如下所示:

<meta-data
android:name="default-url"
android:value="https://example.com/instantapp/experience"/>

This is not much to do, but it’ll be helpful when you want to show a demo to someone on the fly. This is optional.

这没什么大不了的,但是当您想向某人演示演示时,它将很有用。 这是可选的。

要求用户安装完整版本 (Request Users to Install the Full Version)

Now that we’ve configured the instant experience, the next step would be to encourage the user to install the actual app. To do this, first we need to confirm that the user is in the instant experience. We can determine that by using the isInstantApp() method. This method returns true if the running process is in an instant experience.

现在我们已经配置了即时体验,下一步将是鼓励用户安装实际的应用程序。 为此,首先我们需要确认用户是否处于即时体验中。 我们可以使用isInstantApp()方法来确定。 如果正在运行的进程具有即时体验,则此方法返回true

The next step is to show a prompt to the user that encourages them to install the actual app. This can be done as shown below:

下一步是向用户显示提示,鼓励他们安装实际的应用程序。 可以如下所示进行:

class MyInstantExperienceActivity : AppCompatActivity {
    // ...
    private fun showInstallPrompt() {
        val postInstall = Intent(Intent.ACTION_MAIN)
                .addCategory(Intent.CATEGORY_DEFAULT)
                .setPackage(your-installed-experience-package-name)


        // The request code is passed to startActivityForResult().
        InstantApps.showInstallPrompt(this@MyInstantExperienceActivity,
                postInstall, request-code, /* referrer= */ null)
    }
}

测试中 (Testing)

No matter what you do, testing is one of the core things to make it stable. Instant apps can be tested directly by installing from the Android Studio or downloading from the Play store using the internal testing feature.

无论您做什么,测试都是使其保持稳定的核心内容之一。 可以通过从Android Studio安装或使用内部测试功能从Play商店下载直接测试即时应用。

在本地设备中测试 (Test in the local device)

To install directly from Android Studio, execute the following steps:

要直接从Android Studio安装,请执行以下步骤:

  1. First, uninstall if the app is already installed in the device.

    首先,如果该应用程序已经安装在设备中,请卸载。
  2. Then, navigate to the general tab on installation options. Select “deploy as instant app.”

    然后,导航到安装选项上的常规选项卡。 选择“部署为即时应用程序”。
  3. Then click the run button.

    然后单击运行按钮。

内部测试轨道 (Internal test track)

If you’re unsure how the instant app works when it’s downloaded from the Play store, then it’s an excellent time to test it using an internal test track.

如果您不确定从Play商店下载即时应用程序时的工作方式,那么现在是使用内部测试轨道对其进行测试的绝佳时机。

  1. First, generate an Android app bundle as usual.

    首先,像往常一样生成一个Android应用程序捆绑包。
  2. Upload it under the internal test track instead of under production in release management.

    在内部测试轨道上上传它,而不是在发布管理中上载它。
  3. Add your tester’s mail IDs to the testing list.

    将测试人员的邮件ID添加到测试列表中。
  4. Now log in with one of those emails. When you search for the app in the Play store, you’ll see “try now” option.

    现在使用其中一封电子邮件登录。 在Play商店中搜索应用时,您会看到“立即尝试”选项。

奖金 (Bonus)

To learn more about dynamic delivery and Android app bundles, read the following articles:

要了解有关动态投放和Android应用程序捆绑包的更多信息,请阅读以下文章:

I hope you learned something useful — thanks for reading.

我希望您学到了一些有用的东西-感谢您的阅读。

翻译自: https://medium.com/better-programming/everything-you-should-know-about-instant-apps-on-android-2ea83b18dc8e

android应用程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值