简体   繁体   中英

Installed application is third-party or not

How can I get the list of installed third-party applications on Android phone.

I am able to get the list of application with the code below but I want only third-party applications.

PackageManager pm = context.getPackageManager();
appInstalModel.setAppName(p.applicationInfo.loadLabel(context.getPackageManager()).toString());
appInstalModel.setAppPkg(p.packageName);
appInstalModel.setAppVersionName(p.versionName);

RoflcoptrException's answer is correct. But in some cases it won't give you all the installed third-party applications. ApplicationInfo also has flag FLAG_UPDATED_SYSTEM_APP which is set

If this application has been install as an update to a built-in system application

On my smart phone such applications include Amazone Kindle, Adobe Reader, Slacker Radio and others. These applications did not come with the phone and were installed from Google Play Store. Thus, they can be considered as third-party apps.

So, you may also want to check FLAG_UPDATED_SYSTEM_APP flag.

final PackageManager packageManager = _context.getPackageManager();
List<ApplicationInfo> installedApplications = 
    packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo appInfo : installedApplications)
{
    if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
    {
        // IS A SYSTEM APP
    }

    if ((appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
    {
        // APP WAS INSTALL AS AN UPDATE TO A BUILD-IN SYSTEM APP
    }
}
    List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
    for (int i=0; i < apps.size(); i++)
    {
        if ((apps.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 1)
        {
            //System app
       }
    }

The ApplicationInfo object will have the FLAG_SYSTEM flag unset. The sdmove program might have some sample code.

small changes in @Roflcoptr answer.

List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for (int i=0; i < apps.size(); i++)
{
    if ((apps.get(i).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
    {
         //System app
   }
}

Thanks @Roflcoptr for your answer.

public static List<PackageInfo> getInstalledAppList(Context context) {
        ArrayList<PackageInfo> packList = (ArrayList<PackageInfo>) context.getPackageManager().getInstalledPackages(0);
        showLog("/n/n ********************** App List ********************");
        for (int i = 0; i < packList.size(); i++) {

            PackageInfo packInfo = packList.get(i);
            if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                String appName = packInfo.applicationInfo.loadLabel(context.getPackageManager()).toString();
                showLog(appName + "(" + packInfo.packageName + ")");
            } else {
                packList.remove(i);
                i--;
            }
        }

        showLog("List Size : " + packList.size());
        showLog("/n/n ********************** END ********************");
        return packList;
    }

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