My app have system privileges. It will be inside firmware, now it's located at /system/app
I was able to install apps silently with this post
install / uninstall APKs programmatically (PackageManager vs Intents)
example app that works
http://paulononaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/
But I still can't uninstall apps the same way. I tried to use reflection like as in the installation example.
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});
}
I have added uninstallPackage method and edited ApplicationManager method. Still cant get this working.
When I run it I get method not found (on the invoke "deletePackage" line).
Here is not working project with my changes: https://dl.dropbox.com/u/1928109/InstallInBackgroundSample.zip
Here is an description of function: http://www.androidjavadoc.com/1.0_r1_src/android/content/pm/PackageManager.html#deletePackage(java.lang.String, android.content.pm.IPackageDeleteObserver, int)
Parameters are ok. Seems like I should specify DeletePackageObserver class instead of InstallPackageObserver. But I don't know how to do that (I don't have such class).
Thanks
Here is how I did it:
ApplicationManager.java (changed part):
PackageDeleteObserver.java (in android.content.pm):
Also dont forget to add permission to manifest:
Working sample project (apk need to be placed in "/system/app" path on device): http://www.mediafire.com/file/no4buw54ed6vuzo/DeleteInBackgroundSample.zip