简体   繁体   中英

How to remove system app from Android phone programmatically?

I have an app which resides in system memory of the phone. It's a kind of a phone lock app which requires password to access phone.

I need the app disappaer from the phone once a correct password is entered. Right now, what I have done is that I have self uninstalled the app using Intent.DELETE upon correct password. But the problem is that when the phone is factory reset, the app appear again asking for password.

So is there a way to programmatically uninstall the system app, so it doesn't appear even after the phone is factory reset?

I have found a couple of posts here on Stack Overflow but couldn't get the code working.

How to uninstall android system app programmatically?

How to uninstall own app from /system/app?

When you build your application as a preinstalled app (system/app or system/priv-app), it becomes part of the system image and system partition. When the user performs a factory reset, the device falls back to the original system image of the build, in your case, that image includes the application that might have already been uninstalled.

Both solutions that you provided try to delete your application from the system partition that is a read-only partition (and for good reason). If you wish to delete files from that partition, you will have to remount it as read/write partition and only then delete the files.

To remount the system partition you will need a root access, and to my knowledge it will be impossible from inside a standard Android application.

You might want to use an executable Daemon that has root access and performs the deletion for you, but that's a pretty complicated solution.

Edit :

Being a system application doesn't mean the application has root access ! The second example will work only if the whole device is rooted. In that case your device's security is extremely weak. If you still want to use that approach, just provide the path to your apk (system/app/yourapp/yourapp.apk).l

You can execute root commands like this:

private void deleteApk(String packageName) {
    try {   
        final String command = "rm -rf /system/app/" + packageName;
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
        proc.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM