Reputation: 1107
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?
Upvotes: 2
Views: 1356
Reputation: 96
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
Upvotes: 0
Reputation: 1612
INSTALL_PACKAGES permission is only allowed to system apps, installed in /system/app.
For other applications, it's not possible.
Upvotes: 0
Reputation: 109257
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.
Upvotes: 5