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、靜默安裝
源碼較爲複雜,這裏做爲筆記記錄一下。