I want to install an application on Android without user intervention. I am using the permission INSTALL_PACKAGES
and I am installing the app in the "/download/" folder. 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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Sorry, You can't. Android framework doesn't allowed you to do that. Android has a some restriction for Security Purpose, don't try to break it.
回答2:
INSTALL_PACKAGES permission is only allowed to system apps, installed in /system/app.
For other applications, it's not possible.
回答3:
You can use the hidden API android.content.pm.IPackageInstallObserver by reflection :
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. Your app must be system. You must activate the permission android.permission.INSTALL_PACKAGES in your manifest