How Android implements a list of application-related information

Source: Internet
Author: User

This article describes a method for Androdi to get a list of mobile apps, such as acquiring software properties, size and application paths to Android apps, app names, and so on, to get a list of all installed Android apps, including those that have been uninstalled, but that don't erase the data. At the same time, when the application information is obtained, it is not the application of the system, it is a necessary function of an application manager.

The specific implementation code is as follows:

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869 //AppInfoProvider.javapackage 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;/** * 类名称:AppInfoProvider  * 类描述:获取应用程序的相关信息 * 创建人:LXH  */public class AppInfoProvider { private PackageManager packageManager; //获取一个包管理器 public AppInfoProvider(Context context){ packageManager = context.getPackageManager(); } /** *获取系统中所有应用信息, *并将应用软件信息保存到list列表中。 **/ public List<AppInfo> getAllApps(){ List<AppInfo> list = new ArrayList<AppInfo>(); AppInfo myAppInfo;  //获取到所有安装了的应用程序的信息,包括那些卸载了的,但没有清除数据的应用程序  List<PackageInfo> packageInfos = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); for(PackageInfo info:packageInfos){  myAppInfo = new AppInfo();  //拿到包名  String packageName = info.packageName;  //拿到应用程序的信息   ApplicationInfo appInfo = info.applicationInfo;  //拿到应用程序的图标  Drawable icon = appInfo.loadIcon(packageManager);  //拿到应用程序的大小  //long codesize = packageStats.codeSize;  //Log.i("info", "-->"+codesize);  //拿到应用程序的程序名  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; } /** *判断某一个应用程序是不是系统的应用程序, *如果是返回true,否则返回false。 */ public boolean filterApp(ApplicationInfo info){ //有些系统应用是可以更新的,如果用户自己下载了一个系统的应用来更新了原来的,它还是系统应用,这个就是判断这种情况的 if((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0){  return true; }else if((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0){//判断是不是系统应用  return true; } return false; }}

The Java classes associated with the instance are as follows:

?
123456789101112131415161718192021222324252627282930313233343536373839404142434445 //AppInfo.javapackage com.xh.ui;import android.graphics.drawable.Drawable;/** * 类名称:AppInfo  * 类描述:应用程序类,包括了程序相关属性 * 创建人: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 example is provided with detailed comments, which can be improved and perfected based on the understanding of the program function.

How Android implements a list of application-related information

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.