Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:11+00:00 2026-06-05T07:09:11+00:00

My app have system privileges. It will be inside firmware, now it’s located at

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:09:13+00:00Added an answer on June 5, 2026 at 7:09 am

    Here is how I did it:

    ApplicationManager.java (changed part):

    private PackageInstallObserver observer;
    private PackageDeleteObserver observerdelete;
    private PackageManager pm;
    private Method method;
    private Method uninstallmethod;
    
     class PackageDeleteObserver extends IPackageDeleteObserver.Stub { 
    
        public void packageDeleted(String packageName, int returnCode) throws RemoteException {
            /*if (onInstalledPackaged != null) {
                onInstalledPackaged.packageInstalled(packageName, returnCode);
            }*/
        }
    }
    public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
    
    observer = new PackageInstallObserver();
    observerdelete = new PackageDeleteObserver(); 
    pm = context.getPackageManager();
    
    Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
    Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.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, observerdelete, 0});
    }
    

    PackageDeleteObserver.java (in android.content.pm):

    package android.content.pm;
    
    public interface IPackageDeleteObserver extends android.os.IInterface {
    
        public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageDeleteObserver {
            public Stub() {
                throw new RuntimeException("Stub!");
            }
    
            public static android.content.pm.IPackageDeleteObserver asInterface(android.os.IBinder obj) {
                throw new RuntimeException("Stub!");
            }
    
            public android.os.IBinder asBinder() {
                throw new RuntimeException("Stub!");
            }
    
            public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
                    throws android.os.RemoteException {
                throw new RuntimeException("Stub!");
            }
        }
    
        public abstract void packageDeleted(java.lang.String packageName, int returnCode)
                throws android.os.RemoteException;
    }
    

    Also dont forget to add permission to manifest:

    <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
    

    Working sample project (apk need to be placed in “/system/app” path on device):
    http://www.mediafire.com/file/no4buw54ed6vuzo/DeleteInBackgroundSample.zip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My iPhone app will have read-only system data AND read/write user data (stored either
In my app I have a system where I am able to show dialogs
I am planing to display Rss feed inside an Androind app I have this
We have a system where we need to install this on 80+ client machines.
In my cocoa app I have to call system() function to launch an external
I have a 'template' system in my CMS rails app. Basically the whole HTML
Is it allowed (also considering sandboxing) to have your app bypass the system print
I have a PHP app running happily on the following system: web app: PHP
I have a C# app that subscribes to a topic on our messaging system
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.