Question

I'm going to uninstall an application when user click on a button. with this code:

Uri packageURI = Uri.parse("package:"
        + pkNames[position]);
Intent uninstallIntent = new Intent(
Intent.ACTION_DELETE, packageURI);
context.startActivity(uninstallIntent);

but some application don't uninstallable. like Setting or Music or ... when i am going to uninstall these applications i see : uninstall not successful.

I get my packages with this code :

        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        packages = pm.queryIntentActivities(mainIntent, 0);

How can i detect an application is uninstallable or not?

Was it helpful?

Solution

You should check if the application you are trying to uninstall is "system" by looking into ApplicationInfo.flags. System application have ApplicationInfo.FLAG_SYSTEM bit set. Here is a little piece of code:

boolean isSystem(ApplicationInfo info) {
   return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}

Check documentation for ApplicationInfo class for other useful flags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top