How to obtain the getPackageManager () of the VersionName of the Android Project ()
Code notes:
/*** Get the version name in the application-layer sequence ** @ return */private String getVersionName () {// used to manage installed apk and uninstalled apk PackageManager packageManager = getPackageManager (); try {// get the apk function list file: to prevent errors, use getPackageName () method to obtain the package name // packageManager. getPackageInfo ("com. xuliugen. mobilesafe ", 0); PackageInfo packageInfo = packageManager. getPackageInfo (getPackageName (), 0); // return the version name return packageInfo. versionName;} catch (NameNotFoundException e) {e. printStackTrace (); return "";}}
GetPackageManager () API introduction:
Common Methods:
Public abstract PackageManager getPackageManager () function: obtains a PackageManger object.
Public abstract Drawable getApplicationIcon (String packageName) parameter: packageName package name function: return the icon of the given package name; otherwise, return null
Public abstract ApplicationInfo getApplicationInfo (String packageName, int flags) parameter: packagename package name flags the ApplicationInfo is the flags. Generally, you can directly assign a constant 0 to return the ApplicationInfo object.
Public abstract List getInstalledApplications (int flags) parameter: flag is generally GET_UNINSTALLED_PACKAGES, then all ApplicationInfo is returned. We can filter flags of ApplicationInfo to obtain what we need. Function: returns all PackageInfo for a given condition.
Public abstract List
The getInstalledPackages (int flags) parameter is used to return all PackageInfo for a given condition.
Public jsonactresolveinfo resolveActivity (Intent intent, int flags) parameter: intent search condition. The action and category flags: MATCH_DEFAULT_ONLY: Category configured by the Activity must contain the CATEGORY_DEFAULT Activity to match GET_INTENT_FILTERS: GET_RESOLVED_FILTER: matches the Intent condition. function: returns the ResolveInfo object (essentially Activity) of the given condition)
Public abstract List
QueryIntentActivities (Intent intent, int flags) parameter same as above function: return all ResolveInfo objects (essentially Activity) of the given condition, set object
Public abstract ResolveInfo resolveService (Intent intent, int flags) parameter same as above function: returns the ResolveInfo object for the given condition (essentially a Service)
Public abstract List
The queryIntentServices (Intent intent, int flags) parameter is the same as the preceding function: returns all ResolveInfo objects (essentially services) of a given condition, a collection object.
PackageInfo class
Note: You can manually obtain information about the AndroidManifest. xml file.
Common fields:
Public String packageName package name public ActivityInfo [] activities all node information public ApplicationInfo applicationInfo node information, only one public ActivityInfo [] receivers all
Node information, multiple public ServiceInfo [] services all
Node information, multiple
PackageItemInfo class
Note: base classes of all nodes in the AndroidManifest. xml file provide basic information about these nodes: label, icon, and meta-data. It does not
Instead, it is inherited by the subclass and then the corresponding method is called.
ApplicationInfo class inherited from PackageItemInfo
Description: obtains information about nodes in a specified reference program.
Field Description: flags field: FLAG_SYSTEM System Application and FLAG_EXTERNAL_STORAGE indicates that the application is installed in sdcard.
The common methods inherit from loadIcon () and loadLabel () in the PackageItemInfo class ()
The ActivityInfo class is inherited from PackageItemInfo.
Description: obtains information about an application or node. We can use it to obtain any attributes we set, including
Theme, launchMode, launchmode, etc.
The common methods inherit from loadIcon () and loadLabel () in the PackageItemInfo class ()
ServiceInfo class
Note: similar to ActivityInfo, it also inherits from PackageItemInfo, but it represents node information.
ResolveInfo class
Description: obtains the information of the directory on the last layer based on the node, usually, and node information.