10

How do I differentiate between a system app and a normal app ? I looked through android PackageManager and could not find any.

Edit: I want to differentiate via code.

if(system app) {
  //do something
}
else{
   //do nothing
}
Aswin Kumar
  • 4,913
  • 5
  • 28
  • 35
Vinoth
  • 5,297
  • 11
  • 42
  • 56

5 Answers5

16

You could try using the flags available in the ApplicationInfo class (android.conent.pm). For example:

...
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);

for (ApplicationInfo ai: installedApps) {

    if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        // System app - do something here
        ...
    } else {
        // User installed app?
    }
}
Claire Swinson
  • 236
  • 1
  • 4
  • 1
    This is actually not true. Although most installed applications follow the behavior that `Application.FLAG_SYSTEM` would get, some apps can opt not to be installed on the system image (such as on the sd card), and this would not apply. See http://developer.android.com/reference/android/content/pm/ApplicationInfo.html#FLAG_SYSTEM – Phil Jan 09 '12 at 05:48
  • @ClaireSwinson : Phil is correct.Check my answer for a double confirmation method to verify whether an app is a 'real' system app or not. – Basher51 Aug 14 '14 at 05:01
12

Forget PackageManager! You only asked about your own application. Within your Activity#onCreate(Bundle) you can just call getApplicationInfo() and test its flags like this:

boolean isSystemApp = (getApplicationInfo().flags
  & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
gb96
  • 1,552
  • 16
  • 25
  • This is not necessarily true, the solution which @basher51 has mentioned should be the correct answer. The reason is System apps can still be installed outside the system image. These flags only work for apps installed in the device's system image – Monu Surana Sep 13 '16 at 00:47
0

A simple function:

public boolean isUserApp(ApplicationInfo ai,boolean getUpdatedSystemApps){      
    if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        if(getUpdatedSystemApps==true){
            if((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0){
                return true;
            } else {
                return false;
            }                  
        }
        return false;
    } else {
        return true;
    }
}

you can use above function like:

PackageManager pm = getPackageManager();
List<ApplicationInfo> allApps = pm.getInstalledApplications(0);

for (ApplicationInfo ai: allApps) {

    if (isUserApp(ai,true)) {
        // User app or Updated SystemApp - do something here
        ...
    } else {
        // System app
    }
}
Amit Kumar Khare
  • 496
  • 6
  • 16
0

I see a comprehensive answer by Pankaj Kumar in this SO link : "How do I check if an app is a non-system app in Android?" OR in this blog by him : "http://pankajchunchun.wordpress.com/2014/07/08/how-to-check-if-application-is-system-app-or-not-by-signed-signature/" .

Community
  • 1
  • 1
Basher51
  • 1,249
  • 1
  • 17
  • 26
0

For starters, you cant uninstall a system app but you can uninstall a normal app using "Settings > Applications > Manage Applications".

mudit
  • 24,215
  • 30
  • 84
  • 131