Enter the above keywords on Google + android, you can search the code
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0 );
While some code claims to be able to filter out the system's own applications, a closer look at the code will reveal that the Boolean variable in it does not have any filtering effect.
Method one: Through the acquisition of the installation package (including installed with the system itself of the application), its android.content.pm.PackageInfo packagename filter,
But Android and Google's package is easier to filter out, but need to adapt to different producers;
Method Two: Enumerate the \data\app folder, under which the *.apk file is the native installed software, and \system\app under the *.apk file is the system comes with the software,
Because the normal program is unable to read these two folders, need root permission, so this method also does not work (with file.listfiles () + Android.permission.FACTORY_TEST permissions or not to enumerate files)
Although you cannot enumerate the folder "\data\app\", we can access all the files under the (Read) folder "\data\app\", so you can get the software that is already installed on this computer (the application that excludes the system) in the following ways:
Packagemanager Pckman = Getpackagemanager (); list<packageinfo> packs = pckman.getinstalledpackages (0); count = Packs.size (); String Name;int installednum = 0;for (int i = 0; i < count; i++) {PackageInfo p = packs.get (i); if (P.versionname = = null) continue;
method Three, the UID can be used to filter the system's installation package, because the Android system UID from 1000 to 9999 are reserved for the system program, so long as the identification of the package UID > 10000 can be judged that the program is a non-system program.
if (P.applicationinfo.uid > 10000 ) &NBSP;&NBSP;&NBSP; //非系统程序
The UID is assigned by the system when the program is installed.
Method Four: This method should be optimal. This distinction system or third-party software used in ad killers
ApplicationInfo appInfo = p.applicationinfo; /** * Value for {@link #flags}: If set, this application was installed in the * device ' s system image. */if ((Appinfo.flags & Applicationinfo.flag_system) > 0)// System program Else //Not System program
Differentiate system programs and installers in Android