以编程方式安装/卸载APK(PackageManager vs意图)
使用意向安装APK
Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); startActivity(intent);
使用意图卸载APK:
Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).
packageName,null));startActivity(intent);使用PackageManager安装APK
/**
* @hide
*
* Install a package. Since this may take a little while, the result will
* be posted back to the given observer. An installation will fail if the calling context
* lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
* package named in the package file's manifest is already installed, or if there's no space
* available on the device.
*
* @param packageURI The location of the package file to install. This can be a 'file:' or a
* 'content:' URI.
* @param observer An observer callback to get notified when the package installation is
* complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be
* called when that happens. observer may be null to indicate that no callback is desired.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that is performing the是否可以使用intents指定包安装程序名称? (也许可以在安装意图之外添加安装程序包的名称?)
德玛西亚99
相关分类