简体   繁体   English

Android Instant Apps和App LInks的使用

[英]Android Instant Apps and use of App LInks

It looks like right now that Android Instant Apps are supported in Android 5.0 or later. 现在看来Android 5.0或更高版本支持Android Instant Apps。 However, App Links (which I understood that Instant Apps depend on) are only supported in 6.0 or later. 但是,App Links(我理解Instant Apps依赖)仅在6.0或更高版本中受支持。 I've searched online but couldn't find clear answer on this. 我在网上搜索过但无法找到明确的答案。

In general it looks like we'd want, to support Instant apps, to use app links to navigate between activities in different feature modules, but also need in most cases to use those modules to build installable apk that works on versions below 5.0 一般来说,我们希望支持即时应用程序,使用应用程序链接在不同功能模块中的活动之间导航,但在大多数情况下还需要使用这些模块来构建适用于5.0以下版本的可安装apk
Does this mean that code needs to check the API level and use different approaches depending on version (eg calling startActivity with explicit intent if < 5.0)? 这是否意味着代码需要检查API级别并根据版本使用不同的方法(例如,如果<5.0,则调用具有显式意图的startActivity )?

This is the info I've found in the Instant Apps documentation : 这是我在Instant Apps文档中找到的信息:

Both your instant and installable versions of your app must implement the Android App Links feature introduced in Android 6.0 . 您的即时和可安装版本的应用程序都必须实现Android 6.0中引入的Android App Links功能。 App Links provide the primary mechanism for connecting URLs to discrete activities within your app. App Links提供了将URL连接到应用程序中的离散活动的主要机制。

and

an instant app cannot launch an activity in another feature directly; 即时应用无法直接在其他功能中启动活动; instead, it must request the URL address that corresponds to the other other feature's entry-point activity. 相反,它必须请求与其他其他功能的入口点活动相对应的URL地址。

and then from https://developer.android.com/topic/instant-apps/index.html 然后从https://developer.android.com/topic/instant-apps/index.html

Android Instant Apps supports the latest Android devices from Android 5.0 (API level 21) through Android O Android Instant Apps支持Android 5.0 (API级别21)到Android O的最新Android设备

Android App Links just provide a way for Android system to uniquely associate your http deep-links with your application (without showing the disambiguation dialog for the user to select which app to open the link). Android应用链接只是为Android系统提供了一种方式,可以将您的http深层链接与您的应用程序进行唯一关联(无需显示消歧对话框,供用户选择打开链接的应用程序)。 It doesn't give you any new API to start an activity. 它没有为您提供任何新的API来启动活动。 Thus you will need to call startActivity in any case. 因此,您无论如何都需要调用startActivity You just need to use an implicit intent if you want to open an activity belonging to another Instant App feature module. 如果要打开属于另一个即时应用程序功能模块的活动,则只需使用隐式意图。

For navigation inside of the same feature module (or in case your Instant App consists of just one base feature ) an explicit intent could be freely used. 对于同一功能模块内部的导航(或者如果您的Instant App仅包含一个基本功能 ),可以自由使用显式意图。

It looks like right now that Android Instant Apps are supported in Android 5.0 or later. 现在看来Android 5.0或更高版本支持Android Instant Apps。 However, App Links (which I understood that Instant Apps depend on) are only supported in 6.0 or later 但是,App Links(我理解Instant Apps依赖)仅在6.0或更高版本中受支持

Yes, that's true. 是的,这是真的。 But the Instant App supervisor (which is installed internally by the Google Play Services and used to run Instant Apps on Android before 8.0) will ensure that app links registered to your verified Instant App domain will be forwarded directly to your Instant App. 但是,即时应用程序主管(由Google Play服务内部安装并用于在8.0之前在Android上运行即时应用程序)将确保注册到已验证的即时应用程序域的应用程序链接将直接转发到您的即时应用程序。

Does this mean that code needs to check the API level and use different approaches depending on version (eg calling startActivity if < 5.0) 这是否意味着代码需要检查API级别并根据版本使用不同的方法(例如,如果<5.0则调用startActivity

Yes, if you want to be 100% sure your user won't be shown a disambiguation (aka "chooser") dialog like this , while browsing between the activities of your app (and most probably you would like to prevent such a weird user experience). 是的,如果你想确保你的用户将不会显示一个消歧(又名“选配”)对话框100% 这样的 ,而你的应用程序的活动之间浏览(并极有可能要防止这种怪异的用户经验)。 If you use dependency injection, you can have an interface used for navigation in your app, and then different implementations for the installable and the instant app. 如果使用依赖注入,则可以在应用程序中使用用于导航的界面,然后使用可安装和即时应用程序的不同实现。

interface Navigation {
   void startActivityFromModuleA();
   void startActivityFromModuleB();
   …
}

class InstallableAppNavigation implements Navigation {
   public void startActivityFromModuleA() {
       // explicit intent
       Intent intent = new Intent(context, ActivityFromModuleA.class);
       context.startActivity(intent);
   }
   …
}

class InstantAppNavigation implements Navigation {
   public void startActivityFromModuleA() {
       // implicit intent
       Intent intent = new Intent(Intent.ACTION_VIEW,  
               Uri.parse("https://your.app.com/moduleA/smth"));
       context.startActivity(intent);
   }
   …
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM