Android development through Package Manager get installation app information

Source: Internet
Author: User

Recently writing an app yourself, there is a module that needs to get some information about the phone app. Pit still has, but all basically stepped over, oneself put him out, realize method still very need to master. The four options in the bottom pop-up dialog are not explained in more detail, mainly about how to obtain the application information for these installations. Well, not much to say, look:

Get phone installation app info:

1. Write a javabean that is used to store application information and to produce get,set methods.

 Public classAppbean {Privatedrawable AppIcon; PrivateString AppName; Private intappsize; Private BooleanIssd=false; Private Booleanissystem=false; PrivateString AppPackageName;  PublicString Getapkpath () {returnApkpath; }     Public voidSetapkpath (String apkpath) { This. Apkpath =Apkpath; }    PrivateString Apkpath;  PublicString Getapppackagename () {returnAppPackageName; }     Public voidsetapppackagename (String apppackagename) { This. AppPackageName =AppPackageName; }     Publicdrawable Getappicon () {returnAppIcon; }     Public voidSetappicon (drawable appIcon) { This. AppIcon =AppIcon; }     PublicString Getappname () {returnAppName; }     Public voidsetappname (String appName) { This. AppName =AppName; }     Public intgetappsize () {returnappsize; }     Public voidSetappsize (intappsize) {         This. AppSize =appsize; }     Public BooleanisSd () {returnisSd; }     Public voidSETSD (BooleanSD) {IsSd=SD; }     Public BooleanIsSystem () {returnIsSystem; }     Public voidSetsystem (Booleansystem) {IsSystem=system; }}

The properties are written clearly and no more annotations are made here.

2. Write a tool class to get information about the phone installation application through this tool class. As we all know, all Android applications are in package management, basically, an application corresponds to a package information, so we can get through the package Manager, through the Package Manager getinstalledpackages (0), pass a 0, get to all applications. Specific implementation code:

 Public StaticList<appbean>getallapk () {List<appbean>appbeanlist=NewArraylist<>(); Appbean Bean=NULL; Packagemanager Packagemanager=Uiutils.getcontext (). Getpackagemanager (); List<PackageInfo> list=packagemanager.getinstalledpackages (0);  for(PackageInfo p:list) {Bean=NewAppbean ();            Bean.setappicon (P.applicationinfo.loadicon (Packagemanager));            Bean.setappname (Packagemanager.getapplicationlabel (p.applicationinfo). toString ());            Bean.setapppackagename (P.applicationinfo.packagename);            Bean.setapkpath (P.applicationinfo.sourcedir); File File=NewFile (P.applicationinfo.sourcedir); Bean.setappsize ((int) file.length ()); intflags=P.applicationinfo.flags; //determine if the APK is part of the system            if((flags& Applicationinfo.flag_system)!=0) {Bean.setsystem (true); }Else{BEAN.SETSD (true);        } appbeanlist.add (Bean); }        returnappbeanlist; }

Several points to note:

* Get app name to go through packagemanager.getapplicationlabel (p.applicationinfo). toString (), if passed P.applicationinfo.name can't get the app's name.

* Flag is used in Android to identify whether the app is a self-contained application and how to determine it.

*Uiutils.getcontext () is the method I encapsulated to invoke the context contexts.

3. Take out the data display via JavaBean:

Slightly.

Well, the display of data can be displayed by oneself at will, write to this, hope this article for your life and study help. If you want to know the effect of the implementation, you can comment in the comments below, I will next blog update ~

Android development through Package Manager get installation app 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.