Android 免安裝應(yīng)用

什么是免安裝應(yīng)用

Android 免安裝應(yīng)用使原生 Android 應(yīng)用能夠在啟動(dòng)網(wǎng)址時(shí)運(yùn)行,無(wú)需安裝應(yīng)用。 當(dāng) Google Play 商店收到與 免安裝應(yīng)用匹配的網(wǎng)址請(qǐng)求時(shí),它將必需的代碼文件發(fā)送到發(fā)送該請(qǐng)求的 Android 設(shè)備。 然后,該設(shè)備將運(yùn)行此應(yīng)用。

:Android 免安裝應(yīng)用僅在運(yùn)行 Android 5.0(API 級(jí)別 21)或更高版本的 Android 設(shè)備上正常工作。(但更多的是告訴我要在 api 23)

B&H demo 
google給的預(yù)覽,但目前我也沒有在google play上找到
B&H demo google給的預(yù)覽,但目前我也沒有在google play上找到

為什么要使用免安裝應(yīng)用

好處

1.快速(了解與體驗(yàn))
2.輕(因?yàn)槊獍惭b應(yīng)用至少要有一個(gè)開放的功能,可能是核心app,用戶可以直接刪繁就簡(jiǎn)觸碰核心功能)
3.熱點(diǎn)(gp會(huì)推薦一波)

壞處

1.活躍統(tǒng)計(jì)(看將來(lái)gp如何做)
2.流量

:權(quán)限(還是需要的

怎么加入免安裝應(yīng)用

原理

免安裝應(yīng)用中的每項(xiàng)功能應(yīng)至少有一個(gè)可充當(dāng)該功能入口點(diǎn)的 Activity 類。 入口點(diǎn) Activity 可托管此功能的 UI,并定義整個(gè)用戶流。

要提供按需功能下載,您需要將應(yīng)用分解成較小的模塊,并將它們打包成功能模塊。

在構(gòu)建免安裝應(yīng)用項(xiàng)目時(shí),構(gòu)建輸出是一個(gè)包含一個(gè)或多個(gè)功能 APK 的免安裝應(yīng)用 APK。 每項(xiàng)功能 APK 都是從項(xiàng)目中的功能模塊構(gòu)建的,可以由用戶按需下載,并且可以作為免安裝應(yīng)用進(jìn)行啟動(dòng)。

每個(gè)免安裝應(yīng)用都必須有且僅有一個(gè)基礎(chǔ)功能 APK。 如果您的免安裝應(yīng)用只有一項(xiàng)功能,那么,您只需要基礎(chǔ)功能 APK;其他功能 APK 是可選的。如果您的免安裝應(yīng)用具有多項(xiàng)功能,則基礎(chǔ)功能 APK 通常包含其他功能所依賴的共享資源和代碼文件。 像地圖免安裝應(yīng)用一樣,基礎(chǔ) APK 可能包含此地圖應(yīng)用的基礎(chǔ) styles.xml 文件或數(shù)據(jù)結(jié)構(gòu)類,以用于位置和景點(diǎn)建模。 無(wú)論用戶請(qǐng)求哪項(xiàng)功能,均會(huì)下載基礎(chǔ)功能 APK。

除基礎(chǔ)功能 APK 外,您還可以有其他功能 APK。 其他功能 APK 可以包含與某項(xiàng)功能對(duì)應(yīng)的應(yīng)用片段。 功能 APK 包含針對(duì)該功能的入口點(diǎn) Activity,以及該功能所需的任何獨(dú)特資源。

當(dāng)用戶從免安裝應(yīng)用請(qǐng)求一項(xiàng)功能時(shí),他們將獲得兩個(gè)功能 APK:所請(qǐng)求的功能 APK 和基礎(chǔ)功能 APK。 如果同一個(gè)用戶從該免安裝應(yīng)用請(qǐng)求另一項(xiàng)功能,他們可能只會(huì)收到該功能 APK,因?yàn)樗麄円严螺d基礎(chǔ)功能 APK。 當(dāng)然,如果免安裝應(yīng)用只有一項(xiàng)功能,因而只有一個(gè)基礎(chǔ)功能 APK,則用戶只會(huì)收到基礎(chǔ)功能 APK。

需要了解的方面

關(guān)于地址鏈接的應(yīng)用要求
1.所有聲明的意圖過濾器必須同時(shí)支持HTTPS和HTTP協(xié)議
2.使用的APK簽名方案V2相同的證書

受限功能
1.前臺(tái)服務(wù)(而通過servic和content providers和broadcast receivers將無(wú)法啟動(dòng)您的應(yīng)用程序)
2.推送通知
3.免安裝應(yīng)用可以暫時(shí)使用內(nèi)部存儲(chǔ)專用的應(yīng)用程序(gp的文件夾)
4.目前不支持在桌面創(chuàng)建圖標(biāo)
5.更改設(shè)備的設(shè)置
6.但可能訪問廣告
7.持續(xù)的長(zhǎng)聯(lián)接(Persist longer than the instant app)
8.在運(yùn)行免安裝應(yīng)用時(shí),不可能通過代碼下載未認(rèn)證的app...(Run unverified software, run arbitrary native code, or load code dynamically other than the code provided by the Instant Apps runtime.)

:一種即時(shí)應(yīng)用程序無(wú)法使用替代手段繞過上述限制。不要試圖使用由設(shè)備制造商提供定制的API或功能。谷歌將刪除違反這些限制的應(yīng)用程序。

不支持的功能
1.長(zhǎng)時(shí)間運(yùn)行的后臺(tái)服務(wù)
2.broadcast receivers
3外部訪問的content providers
4.content providers
5.通知

硬件加速
Android的即時(shí)應(yīng)用程序支持OpenGL ES 2.0和語(yǔ)境共享組除外。下面的擴(kuò)展支持:

GL_OES_texture_external
EGL_ANDROID_image_native_buffer
EGL_ANDROID_recordable
EGL_KHR_fence_sync

代碼層面

一下以google官方提供的demo為例

關(guān)鍵項(xiàng)目結(jié)構(gòu)

base

1.權(quán)限

<uses-permission android:name="android.permission.INTERNET" />

2.素材
3.文案
4.其他支持庫(kù)

android {
    ...
    baseFeature true
}
dependencies {
    application project(":installed")
    feature project(':features:bye')
    feature project(':features:hello')
    api "com.android.support:appcompat-v7:${rootProject.supportLib}"
}
hello

1.build.gradle

dependencies {
    implementation project(':features:base')
    api ('com.google.android.instantapps:instantapps:1.0.0') {
        // This is to exclude the transitive dependencies for the support library otherwise
        // the project doesn't compile with the error below.
        //
        // > Android dependency 'com.android.support:support-v4' has different version for the compile (23.3.0) and runtime (25.3.1) classpath. You should manually set the same version via DependencyResolution
        exclude group: 'com.android.support'
    }
}

2.AndroidManifest.xml

        <activity
            android:name="com.instantappsamples.feature.hello.HelloActivity"
            android:label="@string/title_activity_hello"
            android:theme="@style/AppTheme">

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter
                android:autoVerify="true"
                android:order="2">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:host="hello-feature.instantappsample.com"
                    android:pathPrefix="/hello"
                    android:scheme="https" />
                <data
                    android:host="hello-feature.instantappsample.com"
                    android:pathPrefix="/hello"
                    android:scheme="http" />

            </intent-filter>

            <meta-data
                android:name="default-url"
                android:value="https://hello-feature.instantappsample.com/hello" />

        </activity>

3.HelloActivity.java

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://hello-feature.instantappsample.com/goodbye"));
                intent.setPackage(getPackageName());
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                startActivity(intent);
            }
        });
    }
bye

1.build.gradle

dependencies {
    implementation project(':features:base')
}

2.AndroidManifest.xml

      <activity
            android:name=".GoodbyeActivity"
            android:label="@string/title_activity_goodbye"
            android:theme="@style/AppTheme">

            <intent-filter
                android:autoVerify="true"
                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="hello-feature.instantappsample.com"
                    android:pathPrefix="/goodbye"
                    android:scheme="https" />

                <data
                    android:host="hello-feature.instantappsample.com"
                    android:pathPrefix="/goodbye"
                    android:scheme="http" />
            </intent-filter>
        </activity>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,675評(píng)論 25 709
  • 月盡繁陰現(xiàn), 庭前花已謝。 枝前獨(dú)徘徊, 唯有亂花泥。
    陳雨森閱讀 283評(píng)論 0 0
  • 夜里常常想起 那年夏天的離別 每一顆淚水都有要傾訴的必要 每一次歡笑都有被遺忘的可能 紛飛的各色的粉筆屑 是永遠(yuǎn)寫...
    成詩(shī)閱讀 311評(píng)論 0 2
  • 2017-11-26昨晚特別想抽煙,忍住了,繼續(xù)堅(jiān)持我想講一下 昨晚的事情,做一個(gè)自我檢討你要記住,妹紙只是喜歡你...
    冷冷的看你們表演閱讀 232評(píng)論 0 0

友情鏈接更多精彩內(nèi)容