[英]android: install app without user intervention
I want to install an application on Android without user intervention. 我想在没有用户干预的情况下在Android上安装应用程序。 I am using the permission
INSTALL_PACKAGES
and I am installing the app in the "/download/" folder. 我正在使用权限
INSTALL_PACKAGES
并且正在“ / download /”文件夹中安装该应用程序。 Once the download is finished, a dialog box appears asking me to install the app. 下载完成后,将出现一个对话框,要求我安装该应用程序。 How to hide this dialog and install the application without user intervention?
如何隐藏此对话框并安装应用程序而无需用户干预?
Sorry, You can't . 抱歉, 您不能 。 Android framework doesn't allowed you to do that.
Android框架不允许您这样做。 Android has a some restriction for Security Purpose , don't try to break it.
Android出于安全目的有一些限制,请不要尝试破坏它。
INSTALL_PACKAGES permission is only allowed to system apps, installed in /system/app. INSTALL_PACKAGES权限仅允许安装在/ system / app中的系统应用程序。
For other applications, it's not possible. 对于其他应用程序,这是不可能的。
You can use the hidden API android.content.pm.IPackageInstallObserver by reflection : 您可以通过反射使用隐藏的API android.content.pm.IPackageInstallObserver:
public class PackageManagement {
public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
public static final int INSTALL_SUCCEEDED = 1;
private static Method installPackageMethod;
private static Method deletePackageMethod;
static {
try {
installPackageMethod = PackageManager.class.getMethod("installPackage", Uri.class, IPackageInstallObserver.class, Integer.TYPE, String.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public static void installPackage(PackageManager pm, Uri mPackageUri, IPackageInstallObserver observer, int installFlags, String installerPackageName) {
try {
installPackageMethod.invoke(pm, mPackageUri, observer, installFlags, installerPackageName);
} catch (Exception e) {
e.printStackTrace();
}
}
} }
Import android.content.pm.IPackageInstallObserver into your Project. 将android.content.pm.IPackageInstallObserver导入您的项目。 Your app must be system.
您的应用必须是系统。 You must activate the permission android.permission.INSTALL_PACKAGES in your manifest
您必须在清单中激活权限android.permission.INSTALL_PACKAGES
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.