Get installed Applications with Name, Package Name, Version and Icon
2010-11-11 16:35
369 查看
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
log(appname + "/t" + pname + "/t" + versionName + "/t" + versionCode + "/t");
}
}
private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
log(appname + "/t" + pname + "/t" + versionName + "/t" + versionCode + "/t");
}
}
private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
相关文章推荐
- Get installed Applications with Name, Package Name, Version
- When install ”matplotlib” with ”pip”, if you get the following error, it means the “freetype” and “png” libraries needed by matplotlib are not installed:
- Android获得安装或者未安装的apk的信息:versionName, packageName, appIcon...
- Android Studio using a library and project with the same package name
- 如何获取Android项目的VersionName的getPackageManager()
- Get OS Name and Version
- How to Get App Name and Version
- Change version information and icon of console applications
- 如何获取Android项目的VersionName的getPackageManager()
- Error applying site theme: A theme with the name "Jet 1011" and version already exists on the server.
- [笔记] How to get the versionCode and versionName of your app
- How to get browser name, version and operating system detail in selenium 2(Web driver)
- Expecting "jsp:param" standard action with "name" and "value" attributes错误
- Building hybrid mobile applications with PhoneGap and IBM WebSphere Portlet Factory
- Get your Advanced Java Programming Degree with these Tutorials and Courses
- linux_ 25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management
- edit view with icon drawable and Tag usage
- [工作积累] NDK通过Java获取package name 和version
- ....conflicts with existing, non-compatible bean definition of same name and class
- apt-get出现Encountered a section with no Package: header, E:Problem with MergeList /var/lib/apt/lists/