This article describes a method for Androdi to get a list of mobile apps, such as acquiring software properties, sizes and application paths, application names, and so on, for Android apps, and getting all the installed Android apps, including those uninstalled, but not clearing the data, At the same time, when obtaining the application information, it is necessary to judge the application of the system, which is the function of an application manager.
The specific implementation code is as follows:
Appinfoprovider.java package com.xh.ui;
Import java.util.ArrayList;
Import java.util.List;
Import Android.content.Context;
Import Android.content.pm.ApplicationInfo;
Import Android.content.pm.PackageInfo;
Import Android.content.pm.PackageManager;
Import android.graphics.drawable.Drawable; /** * Class Name: Appinfoprovider * Class Description: Get information about the application * Creator: Lxh/public class Appinfoprovider {private Packagemanager pack
Agemanager;
Gets a package Manager public Appinfoprovider {packagemanager = Context.getpackagemanager ();
/** * Gets all the application information in the system, * and saves the application information to the list.
**/public list<appinfo> Getallapps () {list<appinfo> List = new arraylist<appinfo> ();
AppInfo Myappinfo; Gets information about all installed applications, including those that were uninstalled, but did not erase data list<packageinfo> PackageInfos =
Packagemanager.getinstalledpackages (packagemanager.get_uninstalled_packages);
for (PackageInfo info:packageinfos) {myappinfo = new AppInfo ();
Get the package name String PackageName = info.packagename; Get the application information APPLIcationinfo appInfo = Info.applicationinfo;
Get the app icon drawable icon = Appinfo.loadicon (Packagemanager);
Get the size of the application//long codesize = packagestats.codesize;
LOG.I ("info", "-->" +codesize);
Get the application's program name String appName = Appinfo.loadlabel (Packagemanager). toString ();
Myappinfo.setpackagename (PackageName);
Myappinfo.setappname (AppName);
Myappinfo.seticon (icon);
if (Filterapp (AppInfo)) {Myappinfo.setsystemapp (false);
}else{Myappinfo.setsystemapp (TRUE);
} list.add (Myappinfo);
} return list;
/** * Determines whether an application is a system application, * returns False if it returns true. /public Boolean Filterapp (ApplicationInfo info) {//Some system applications can be updated, if the user downloads a system application to update the original, it is the system application, this is to determine the situation of the IF (
Info.flags & Applicationinfo.flag_updated_system_app)!= 0) {return true;
}else if ((Info.flags & applicationinfo.flag_system) = = 0) {//Determine if the system applies return true;
return false;
}
}
The
Instance-related Java classes are as follows:
//appinfo.java package com.xh.ui; import android.graphics.drawable.Drawable;/** * Class Name:
AppInfo * Class Description: Application classes, including program-related properties * Creator: LXH * * public class AppInfo {private drawable icon;
Private String AppName;
Private String PackageName;
Private Boolean Issystemapp;
Private long codesize;
Public long Getcodesize () {return codesize;
} public void Setcodesize (long codesize) {this.codesize = codesize;
Public drawable GetIcon () {return icon;
public void SetIcon (drawable icon) {This.icon = icon;
Public String Getappname () {return appName;
} public void Setappname (String appName) {this.appname = AppName;
Public String Getpackagename () {return packagename;
} public void Setpackagename (String packagename) {this.packagename = PackageName;
public Boolean Issystemapp () {return issystemapp;
} public void Setsystemapp (Boolean issystemapp) {This.issystemapp = Issystemapp; }
}
The
instance is equipped with detailed annotations that can be improved and perfected by the reader based on the understanding of the program's functionality.