不,出于安全原因,这是不可能的。您可以启动安装,但由用户决定。
但是,如果手机已植根,则可以通过编程方式执行此操作,但这不是大多数应用程序的选项。代码与此类似:
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
observer = new PackageInstallObserver();
pm = context.getPackageManager();
Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
Class<?>[] uninstalltypes = new Class[] {String.class, IPackageInstallObserver.class, int.class};
method = pm.getClass().getMethod("installPackage", types);
uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}
public void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
uninstallmethod.invoke(pm, new Object[] {packagename, observer, 0});
}
public void installPackage(Uri apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
method.invoke(pm, new Object[] {apkFile, observer, INSTALL_REPLACE_EXISTING, null});
}
更多细节在这里:
以编程方式安装/卸载 APK(PackageManager 与 Intents)
https://paulonaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/