ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android Instant Apps和App LInks的使用

2019-06-22 13:14:01  阅读:260  来源: 互联网

标签:android deep-linking applinks android-instant-apps


现在看来Android 5.0或更高版本支持Android Instant Apps.但是,App Links(我理解Instant Apps依赖)仅在6.0或更高版本中受支持.我在网上搜索过但无法找到明确的答案.

一般来说,我们希望支持即时应用程序,使用应用程序链接在不同功能模块中的活动之间导航,但在大多数情况下还需要使用这些模块来构建适用于5.0以下版本的可安装apk
这是否意味着代码需要检查API级别并根据版本使用不同的方法(例如,如果< 5.0则调用具有显式意图的startActivity)? 这是我在Instant Apps documentation中找到的信息:

Both your instant and installable versions of your app must implement
the Android App Links feature introduced in Android 6.0. App Links
provide the primary mechanism for connecting URLs to discrete
activities within your app.

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.

然后从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应用链接只是为Android系统提供了一种方式,可以将您的http深层链接与您的应用程序进行唯一关联(无需显示消歧对话框,供用户选择打开链接的应用程序).它没有为您提供任何新的API来启动活动.因此,您无论如何都需要调用startActivity.如果要打开属于另一个即时应用程序功能模块的活动,则只需使用隐式意图.

对于同一功能模块内部的导航(或者如果您的Instant App仅包含one base feature),可以自由使用明确的意图.

It looks like right now that Android Instant Apps are supported in
Android 5.0 or later. However, App Links (which I understood that
Instant Apps depend on) are only supported in 6.0 or later

是的,这是真的.但是,即时应用程序主管(由Google Play服务内部安装并用于在8.0之前在Android上运行即时应用程序)将确保注册到已验证的即时应用程序域的应用程序链接将直接转发到您的即时应用程序.

Does this mean that code needs to check the API level and use
different approaches depending on version (e.g calling startActivity
if < 5.0)

是的,如果你想100%确定你的用户不会在你的应用程序的活动之间浏览时显示消歧(也就是“选择器”)对话框like this(并且很可能你想要防止这种奇怪的用户体验).如果使用依赖注入,则可以在应用程序中使用用于导航的界面,然后使用可安装和即时应用程序的不同实现.

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);
   }
   …
}

标签:android,deep-linking,applinks,android-instant-apps
来源: https://codeday.me/bug/20190622/1263939.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有