搜索
您的当前位置:首页正文

Android 免安装应用

来源:二三娱乐

什么是免安装应用

Android 免安装应用使原生 Android 应用能够在启动网址时运行,无需安装应用。 当 Google Play 商店收到与 免安装应用匹配的网址请求时,它将必需的代码文件发送到发送该请求的 Android 设备。 然后,该设备将运行此应用。

:Android 免安装应用仅在运行 Android 5.0(API 级别 21)或更高版本的 Android 设备上正常工作。(但更多的是告诉我要在 api 23)

关键项目结构
base

1.权限

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

2.素材
3.文案
4.其他支持库

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:pathPrefix="/hello"
                    android:scheme="https" />
                <data
                    
                    android:pathPrefix="/hello"
                    android:scheme="http" />

            </intent-filter>

            <meta-data
                android:name="default-url"
                 />

        </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,
                        
                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:pathPrefix="/goodbye"
                    android:scheme="https" />

                <data
                    
                    android:pathPrefix="/goodbye"
                    android:scheme="http" />
            </intent-filter>
        </activity>
Top