ali shariat
ali shariat

Reputation: 43

How can detect an application is uninstallable?

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?

Upvotes: 4

Views: 1219

Answers (1)

Darth Beleg
Darth Beleg

Reputation: 2667

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.

Upvotes: 3

Related Questions