Android Simple Combat Tutorial--The 11th session of "Get mobile phone all application information engine class"

Source: Internet
Author: User

If you want to get detailed information about your system's phone app, the code below can be used directly as a template. I have commented on each line of code for your reference. Directly on the code:

Package Com.example.itydl.engines;import Java.io.file;import Java.util.arraylist;import java.util.List;import Com.example.itydl.domain.appbean;import Android.content.context;import Android.content.pm.applicationinfo;import Android.content.pm.packageinfo;import Android.content.pm.packagemanager;import android.os.Environment;/** * Engine class, get all installed apk details * @author YDL * */public class Appmanagerengine {/** * * @param context * @return * SD card free space, unit by Te */public Static long Getsdavailspace (context context) {Long sdavalispace = 0;//get SD card directory file Externalstoragedirectory = Environment.getexternalstoragedirectory ();//Get the available space for the SD card. The remaining space size is calculated indirectly through the folder Sdavalispace = Externalstoragedirectory.getfreespace ();//Returns the remaining data to return sdavalispace;} /** * * @param context * @return * The remaining space in the phone rom */public static long Getromavailspace (context context) {Long romavalispace = 0;//get rom all directory structure file DataDirectory = Environment.getdatadirectory ();//Get ROM free space. Indirect calculation of the remaining space size by folder Romavalispace = Datadirectory.getfreespace ();//Returns the remaining data obtained to return romavalispace;} /** * * @param context * @return * all installed apk details */public static list<appbean> Getallinstalledapks (Context context ) {list<appbean> Apksbean = new arraylist<appbean> ();//Get Package Manager Packagemanager Manager = Context.getpackagemanager ()///through the Package Manager object, get all the installed apk information list<packageinfo> installedpackages = Manager.getinstalledpackages (0);//return a List of all packages that is installed on the device.//traverse all application package information, respectively, to get the details of each app package Information. The application's data can be displayed on the interface for the for (PackageInfo packageinfo:installedpackages) {///to encapsulate the application information of each package into JavaBean. Create the Appbean class Appbean bean = new Appbean ();//Set the APK's package name Bean.setpackname (packageinfo.packagename);//Set the name of the APK, Remember Bean.setappname (manager) + "");//loadlabel (manager) get tag// Set the APK icon Bean.seticon (PackageInfo.applicationInfo.loadIcon (manager));//Set the size of the APK. By getting the apk file, you indirectly get the space size of the APK, string sourcedir = packageinfo.applicationinfo.sourcedir;//Get a path to the app//get the path to the file filename = New File (SourceDir);//Gets the size of the APK, in bytes bean.sEtsize (File.length ());//returns the length of this file in bytes. Depending on the flag bit, whether the system apk or user apk//gets the flag attribute of the APK, int flag = packageinfo.applicationinfo.flags;//Determines whether the system is apkif (flag& Applicationinfo.flag_system) (!=0) {//applicationinfo.flag_system denotes the system's flag flag for the APK//is the system's Apkbean.setsystem (TRUE);// is the system-applied tag}else{//not the system's Apkbean.setsystem (FALSE);} Determine if the application is installed on the system or SDIF ((Flag & Applicationinfo.flag_external_storage)!=0) {//installed on SD card BEAN.SETSD (TRUE);//SD card Tag} ELSE{BEAN.SETSD (false); the tag in//rom}//encapsulates the information object of each apk that is acquired into the data source Model layer Apksbean.add (bean);} return Apksbean;}}


Android Simple Combat Tutorial--The 11th session of "Get mobile phone all application information engine class"

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.