Android intermediate-level system programs and installers

Source: Internet
Author: User

Android intermediate-level system programs and installers

21:37:08

Source: http://www.cnblogs.com/mengshu-lbq/archive/2010/09/09/1822237.html

Enter the above keywords + android on Google, and you can find the code:


1
List<PackageInfo> packs = getPackageManager().getInstalledPackages(
0
);


 


Although some code claims to be able to filter out the system's own applications, as long as you look at the code, you will find that the Boolean variable in it does not play a role in filtering.


  Method 1
: Filter the packagename of Android. content. PM. packageinfo by obtaining the installation package (including the installed and system applications,


However, the anrodi and Google packages are easier to filter out, but different vendors need to be adapted;


  Method 2
: Enumeration/data/APP folder. The *. APK file under it is the software installed on the local machine, and the *. APK file under/system/APP is the software that comes with the system,


Because normal programs cannot read these two folders, the root permission is required, so this method does not work (using file. listfiles () + android. permission. factory_test permission still cannot enumerate files)


Although the folder "/data/APP/" cannot be enumerated, we can access all the files in the (read) folder "/data/APP, therefore, you can use the following method to obtain software installed on the local machine (excluding system applications ):


01
PackageManager pckMan = getPackageManager();
02
List<PackageInfo> packs = pckMan.getInstalledPackages(
0
);
03
count = packs.size();
04
String name;
05
int
installedNum =
0
;
06
for
(
int
i =
0
; i < count; i++) {
07
                
PackageInfo p = packs.get(i);
08
    
if
(p.versionName ==
null
)
09
        
continue
;
10
   
 
01
             
// Determine whether the software package is in the/data/APP directory
02
    
File f1 =
new
File( 
"/data/app/"
+  p.packageName +
".apk"
);
03
    
if
(!f1.exists())
continue
;
04
 
05
    
installedNum++;
06
    
/**
07
     
* Application name
08
     
*/
09
    
name = p.applicationInfo.loadLabel(pckMan).toString();
10
}


Method 3
, You can use UID to filter the installation packages of the system, because the uid in the Android system is from 1000 ~ 9999 is reserved for the system program, so you only need to judge the UID> 10000 of the package to determine that the program is a non-system program.


1
if
(p.applicationInfo.uid >
10000
)
2
   
// Non-system program


 


UID is allocated by the system during installation.


Method 4: This method should be optimal.


1
ApplicationInfo appInfo = p.applicationInfo;
2
    
/**
3
     
* Value for {@link #flags}: if set, this application is installed in the
4
     
* device's system image.
5
     
*/
6
if
((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) >
0
)
7
    
// System Program
8
else

// Not a system program



Android source code
COM/Android/settings/manageapplications. Java

If (filteroption = filter_apps_third_party) {<br/> List <applicationinfo> applist = new arraylist <applicationinfo> (); <br/> for (applicationinfo appinfo: installedapplist) {<br/> Boolean flag = false; <br/> If (appinfo. flags & applicationinfo. flag_updated_system_app )! = 0) {<br/> // updated system app <br/> flag = true; <br/>} else if (appinfo. flags & applicationinfo. flag_system) = 0) {<br/> // non-system app <br/> flag = true; <br/>}< br/> If (FLAG) {<br/> applist. add (appinfo); <br/>}< br/>}

Related Article

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.