1、有界面安装
源码位置:http://www.androidos.net.cn/android/7.1.1_r28/xref/packages/apps/PackageInstaller/AndroidManifest.xml
当我们点击安装apk时,就会在AndroidManifest.xml中找到PackageInstallerActivity类,然后就会展示安装页面。
源码如下:
<activity android:name=".PackageInstallerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true">
<intent-filter android:priority="1">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.INSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
//这里配置了application/vnd.android.package-archive字符串的mime类型
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
<intent-filter android:priority="1">
<action android:name="android.intent.action.INSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="package" />
<data android:scheme="content" />
</intent-filter>
<intent-filter android:priority="1">
<action android:name="android.content.pm.action.CONFIRM_PERMISSIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
然后安装InstallAppProgress.class 正在安装页面,可以进行取消,有安装成功和失败的监听。
2、静默安装
源码较为复杂,这里做为笔记记录一下。