Android 即时应用程序设计

标签 android android-instant-apps

我正在开发一个 Android 应用程序,我也在其中使用即时应用程序功能。在主要功能模块中,我有一个抽屉导航,其中几乎没有导航 View 项。

  1. 电视
  2. 电影
  3. 搜索

当用户点击电视项目时,它将打开具有标签布局的 fragment 。

  1. 热门
  2. 受欢迎
  3. 看过

我必须在设计应用程序时牢记它也应该支持即时应用程序功能。如果用户请求电视,那么它应该只下载电视模块。

我已经创建了一个应用程序、基础、即时应用程序、主要模块。我在主模块中创建了启动器 Activity 并设置了应用程序的 NavigationDrawer。我正在考虑为电视创建另一个模块,它将有 tablayout a) 趋势 b) 流行 c) 观看( fragment )

AndroidManifest.xml(主模块)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.main">

    <application>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:host="example.com" />
                <data android:pathPattern="/main" />
                <data android:scheme="https" />
                <data android:scheme="http" />

            </intent-filter>
        </activity>
    </application>

</manifest>

根据免安装应用程序的概念,我在基础模块中保留了样式、可绘制对象、布局和服务等常见内容以及一些 Activity 。

由于电视模块仅包含选项卡布局,因此它只会包含 fragment - 热门、热门、已观看。

有谁知道如何为电视功能模块设置不同的 URL,以便它可以使用不同的地址访问,例如 https://www.example.com/tv ?如果我在主模块中做所有这些事情,那么即时应用程序功能概念将失败。

我是即时应用程序的新手,不知道我在这里是否也使用了正确的方法。如果有经验的人可以帮助我,我将不胜感激。

最佳答案

每个功能 apk 都需要有一个 Activity 作为入口点,该入口点是可通过 URL 寻址的。考虑到这一点,tv 功能模块 中将需要包含一个 TvActivity。此 Activity 可以包含加载不同电视中心 fragment 的选项卡布局。

电视功能模块中的 AndroidManifest.xml 文件将如下所示:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.main.tv">

<application>
    <activity android:name=".TvActivity">
        <intent-filter android:order="1">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data android:host="example.com" />
            <data android:path="/tv" />
            <data android:scheme="https" />
            <data android:scheme="http" />

        </intent-filter>
    </activity>
</application>

当从 NavigationDrawer 点击 TV 时,它应该触发一个 Intent 来启动 URL https://example.com/tv 这将下载功能 apk(如果需要)并启动 TvActivity

关于Android 即时应用程序设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45999458/

相关文章:

android - Android 10 上的 Mifare 卡模拟?

java - Android应用程序不同布局尺寸的问题

Android Instant App 无需经过验证的网站

java - 如何在不同类中使用两个 onClickListener 引用布局

android - 在android中填充编辑文本的语音输入?

android - 如何正确应用语言?

android - Instant app 中的功能模块重复属性 AAPT2 链接失败

android - "minSdkVersion"用于 InstantApp 支持?

Android Instant 应用程序无法通过应用程序链接在我的 Beta 预发布测试中运行

Android Instant 应用程序未显示