Differentiate system programs and installers in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.